diff --git a/lib/active_hash/base.rb b/lib/active_hash/base.rb index 0898047..144a0c3 100644 --- a/lib/active_hash/base.rb +++ b/lib/active_hash/base.rb @@ -102,12 +102,12 @@ def data=(array_of_hashes) end end - def exists?(args = nil) + def exists?(args = :none) if args.respond_to?(:id) record_index[args.id.to_s].present? - elsif args == false + elsif !args false - elsif args.nil? + elsif args == :none all.present? elsif args.is_a?(Hash) all.where(args).present? diff --git a/spec/active_hash/base_spec.rb b/spec/active_hash/base_spec.rb index d0af652..9d175e4 100644 --- a/spec/active_hash/base_spec.rb +++ b/spec/active_hash/base_spec.rb @@ -1169,6 +1169,12 @@ def continent end end + context "when nil is passed" do + it "return nil" do + expect(Country.exists?(nil)).to be_falsy + end + end + describe "with matches" do context 'for a record argument' do it "return true" do