diff --git a/lib/active_hash/base.rb b/lib/active_hash/base.rb index 4bffad2..00d836b 100644 --- a/lib/active_hash/base.rb +++ b/lib/active_hash/base.rb @@ -113,7 +113,7 @@ def exists?(args = :none) elsif args.is_a?(Hash) all.where(args).present? else - all.where(id: args.to_i).present? + all.where(id: args.to_s).present? end end diff --git a/spec/active_hash/base_spec.rb b/spec/active_hash/base_spec.rb index c268815..c9420e5 100644 --- a/spec/active_hash/base_spec.rb +++ b/spec/active_hash/base_spec.rb @@ -1246,6 +1246,16 @@ def continent end end end + + context "when ids are strings" do + before do + Country.all.each { |c| c.id = c.name } + end + + it "return true" do + expect(Country.exists?("Canada")).to be_truthy + end + end end describe "#method_missing" do