From a3313fcc68b61d9b4aa0cf698d33cbd54b20831f Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 13:25:03 -0500 Subject: [PATCH 01/10] Using .count to implement any? one? and many?, adding testing --- .gitignore | 1 + lib/mongoid/criteria/findable.rb | 30 ++++ lib/mongoid/findable.rb | 3 + spec/mongoid/criteria/findable_spec.rb | 206 +++++++++++++++++++++++++ 4 files changed, 240 insertions(+) diff --git a/.gitignore b/.gitignore index fed26118c1..889af62020 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ examples .env.private* build rspec.xml +x.rb \ No newline at end of file diff --git a/lib/mongoid/criteria/findable.rb b/lib/mongoid/criteria/findable.rb index 450b028814..07b3021c51 100644 --- a/lib/mongoid/criteria/findable.rb +++ b/lib/mongoid/criteria/findable.rb @@ -81,6 +81,36 @@ def multiple_from_db(ids) ids.empty? ? [] : from_database(ids) end + # Return true if any documents exist in the criteria. + # + # @example Determine if any documents exist + # criteria.any? + # + # @return [ true | false ] If any documents exist. + def any? + limit(1).count > 0 + end + + # Return true if only one document exists in the criteria. + # + # @example Determine if only one document exists + # criteria.one? + # + # @return [ true | false ] If only one document exists. + def one? + limit(2).count == 1 + end + + # Return true if more than one document exists in the criteria. + # + # @example Determine if many documents exist + # criteria.many? + # + # @return [ true | false ] If many documents exist. + def many? + limit(2).count > 1 + end + private # Get the finder used to generate the id query. diff --git a/lib/mongoid/findable.rb b/lib/mongoid/findable.rb index 34748f7c7e..d3fb43abf6 100644 --- a/lib/mongoid/findable.rb +++ b/lib/mongoid/findable.rb @@ -17,6 +17,7 @@ module Findable # directly from the class level. def_delegators :with_default_scope, :aggregates, + :any?, :avg, :create_with, :distinct, @@ -40,10 +41,12 @@ module Findable :fourth!, :includes, :last!, + :many?, :map_reduce, :max, :min, :none, + :one?, :pick, :pluck, :raw, diff --git a/spec/mongoid/criteria/findable_spec.rb b/spec/mongoid/criteria/findable_spec.rb index 1468fc5f80..7709a4d338 100644 --- a/spec/mongoid/criteria/findable_spec.rb +++ b/spec/mongoid/criteria/findable_spec.rb @@ -1302,6 +1302,212 @@ end end + describe "#any?" do + context "when called on criteria" do + let!(:band) do + Band.create!(name: "Depeche Mode") + end + + let!(:band_two) do + Band.create!(name: "Radiohead") + end + + context "when documents exist" do + + let(:criteria) do + Band.all + end + + it "returns true" do + expect(criteria.any?).to be true + end + end + + context "when no documents exist" do + + let(:criteria) do + Band.where(name: "Nonexistent Band") + end + + it "returns false" do + expect(criteria.any?).to be false + end + end + end + + context "when called on class" do + context "with documents" do + before do + Band.create!(name: "New Band") + end + + it "returns true" do + expect(Band.any?).to be true + end + end + + context "with no documents" do + before do + Band.delete_all + end + it "returns false" do + expect(Band.any?).to be false + end + end + end + end + + describe "#one?" do + context "when called on criteria" do + let!(:band) do + Band.create!(name: "Depeche Mode") + end + + let!(:band_two) do + Band.create!(name: "Radiohead") + end + + context "when one document exists in criteria" do + let(:criteria) do + Band.where(name: "Depeche Mode") + end + + it "returns true" do + expect(criteria.one?).to be true + end + end + + context "when multiple documents exist in criteria" do + let(:criteria) do + Band.all + end + + it "returns false" do + expect(criteria.one?).to be false + end + end + + context "when no documents exist in criteria" do + let(:criteria) do + Band.where(name: "Nonexistent Band") + end + + it "returns false" do + expect(criteria.one?).to be false + end + end + end + + context "when called on class" do + context "with no documents" do + before do # can maybe delete this - not sure how cleanup works here + Band.delete_all + end + + it "returns false" do + expect(Band.one?).to be false + end + end + + context "with one document" do + before do + Band.create!(name: "Another Band") + end + + it "returns true" do + expect(Band.one?).to be true + end + end + + context "with multiple documents" do + before do + Band.create!(name: "New Band") + Band.create!(name: "Yet Another Band") + end + + it "returns false" do + expect(Band.one?).to be false + end + end + end + end + + describe "#many?" do + context "when called on criteria" do + let!(:band) do + Band.create!(name: "Depeche Mode") + end + + let!(:band_two) do + Band.create!(name: "Radiohead") + end + + context "when multiple documents exist in criteria" do + let(:criteria) do + Band.all + end + + it "returns true" do + expect(criteria.many?).to be true + end + end + + context "when one document exists in criteria" do + let(:criteria) do + Band.where(name: "Depeche Mode") + end + + it "returns false" do + expect(criteria.many?).to be false + end + end + + context "when no documents exist in criteria" do + let(:criteria) do + Band.where(name: "Nonexistent Band") + end + + it "returns false" do + expect(criteria.many?).to be false + end + end + + end + + context "when called on class" do + context "with no documents" do + before do + Band.delete_all + end + + it "returns false" do + expect(Band.many?).to be false + end + end + + context "with one document" do + before do + Band.create!(name: "Another Band") + end + + it "returns false" do + expect(Band.many?).to be false + end + end + + context "with multiple documents" do + before do + Band.create!(name: "New Band") + Band.create!(name: "Yet Another Band") + end + + it "returns true" do + expect(Band.many?).to be true + end + end + end + end + describe '#from_database_selector' do let(:criteria) { Mongoid::Criteria.new(Band) } let(:result) { criteria.send(:from_database_selector, [1]) } From 310a2d035f4fb2b6a16b56ad1f68cd745e2c49e0 Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 13:26:53 -0500 Subject: [PATCH 02/10] Reverting change to .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 889af62020..fed26118c1 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,3 @@ examples .env.private* build rspec.xml -x.rb \ No newline at end of file From 0412484bb512a31f5ebcf236f272135e08977e27 Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 14:00:30 -0500 Subject: [PATCH 03/10] removing unneeded code --- spec/mongoid/criteria/findable_spec.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/spec/mongoid/criteria/findable_spec.rb b/spec/mongoid/criteria/findable_spec.rb index 7709a4d338..778af8fb4a 100644 --- a/spec/mongoid/criteria/findable_spec.rb +++ b/spec/mongoid/criteria/findable_spec.rb @@ -1347,9 +1347,6 @@ end context "with no documents" do - before do - Band.delete_all - end it "returns false" do expect(Band.any?).to be false end @@ -1400,10 +1397,6 @@ context "when called on class" do context "with no documents" do - before do # can maybe delete this - not sure how cleanup works here - Band.delete_all - end - it "returns false" do expect(Band.one?).to be false end @@ -1476,10 +1469,6 @@ context "when called on class" do context "with no documents" do - before do - Band.delete_all - end - it "returns false" do expect(Band.many?).to be false end From 8d8b8ae855206db7b6d7c32b22354746f0cf087a Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 14:44:20 -0500 Subject: [PATCH 04/10] Allowing a block of code/optional args to be passed to better align with Ruby's any? method --- lib/mongoid/criteria/findable.rb | 33 ++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/mongoid/criteria/findable.rb b/lib/mongoid/criteria/findable.rb index 07b3021c51..32d2019f46 100644 --- a/lib/mongoid/criteria/findable.rb +++ b/lib/mongoid/criteria/findable.rb @@ -86,29 +86,50 @@ def multiple_from_db(ids) # @example Determine if any documents exist # criteria.any? # + # @example Determine if any documents match a block + # criteria.any? { |doc| doc.name == "John" } + # + # @param [ Object... ] *args Args to delegate to the target. + # + # @param [ Proc ] &block Block to delegate to the target. + # # @return [ true | false ] If any documents exist. - def any? - limit(1).count > 0 + def any?(*args, &block) + return entries.any?(*args, &block) if args.any? || block_given? end # Return true if only one document exists in the criteria. # # @example Determine if only one document exists # criteria.one? + # + # @example Determine if only one document matches a block + # criteria.one? { |doc| doc.name == "John" } + # + # @param [ Object... ] *args Args to delegate to the target. + # + # @param [ Proc ] &block Block to delegate to the target. # # @return [ true | false ] If only one document exists. - def one? - limit(2).count == 1 + def one?(*args, &block) + return entries.one?(*args, &block) if args.any? || block_given? end # Return true if more than one document exists in the criteria. # # @example Determine if many documents exist # criteria.many? + # + # @example Determine if many documents match a block + # criteria.many? { |doc| doc.name.start_with?("J") } + # + # @param [ Object... ] *args Args to delegate to the target. + # + # @param [ Proc ] &block Block to delegate to the target. # # @return [ true | false ] If many documents exist. - def many? - limit(2).count > 1 + def many?(*args, &block) + return entries.many?(*args, &block) if args.any? || block_given? end private From 6cf4b367f9a9d2ab9fb9856e8b5439280f8d309b Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 15:12:49 -0500 Subject: [PATCH 05/10] Small change --- lib/mongoid/criteria/findable.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/mongoid/criteria/findable.rb b/lib/mongoid/criteria/findable.rb index 32d2019f46..b869e077de 100644 --- a/lib/mongoid/criteria/findable.rb +++ b/lib/mongoid/criteria/findable.rb @@ -96,6 +96,8 @@ def multiple_from_db(ids) # @return [ true | false ] If any documents exist. def any?(*args, &block) return entries.any?(*args, &block) if args.any? || block_given? + + limit(1).count > 0 end # Return true if only one document exists in the criteria. @@ -113,6 +115,8 @@ def any?(*args, &block) # @return [ true | false ] If only one document exists. def one?(*args, &block) return entries.one?(*args, &block) if args.any? || block_given? + + limit(2).count == 1 end # Return true if more than one document exists in the criteria. @@ -130,6 +134,8 @@ def one?(*args, &block) # @return [ true | false ] If many documents exist. def many?(*args, &block) return entries.many?(*args, &block) if args.any? || block_given? + + limit(2).count > 1 end private From e05533629fd0a1688aca49233b9759166719c7a5 Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 16:21:34 -0500 Subject: [PATCH 06/10] Moving from Criteria::Findable to avoid clobbering Enumerable#any? --- lib/mongoid/criteria/findable.rb | 57 -------------------------------- lib/mongoid/findable.rb | 31 ++++++++++++++++- 2 files changed, 30 insertions(+), 58 deletions(-) diff --git a/lib/mongoid/criteria/findable.rb b/lib/mongoid/criteria/findable.rb index b869e077de..450b028814 100644 --- a/lib/mongoid/criteria/findable.rb +++ b/lib/mongoid/criteria/findable.rb @@ -81,63 +81,6 @@ def multiple_from_db(ids) ids.empty? ? [] : from_database(ids) end - # Return true if any documents exist in the criteria. - # - # @example Determine if any documents exist - # criteria.any? - # - # @example Determine if any documents match a block - # criteria.any? { |doc| doc.name == "John" } - # - # @param [ Object... ] *args Args to delegate to the target. - # - # @param [ Proc ] &block Block to delegate to the target. - # - # @return [ true | false ] If any documents exist. - def any?(*args, &block) - return entries.any?(*args, &block) if args.any? || block_given? - - limit(1).count > 0 - end - - # Return true if only one document exists in the criteria. - # - # @example Determine if only one document exists - # criteria.one? - # - # @example Determine if only one document matches a block - # criteria.one? { |doc| doc.name == "John" } - # - # @param [ Object... ] *args Args to delegate to the target. - # - # @param [ Proc ] &block Block to delegate to the target. - # - # @return [ true | false ] If only one document exists. - def one?(*args, &block) - return entries.one?(*args, &block) if args.any? || block_given? - - limit(2).count == 1 - end - - # Return true if more than one document exists in the criteria. - # - # @example Determine if many documents exist - # criteria.many? - # - # @example Determine if many documents match a block - # criteria.many? { |doc| doc.name.start_with?("J") } - # - # @param [ Object... ] *args Args to delegate to the target. - # - # @param [ Proc ] &block Block to delegate to the target. - # - # @return [ true | false ] If many documents exist. - def many?(*args, &block) - return entries.many?(*args, &block) if args.any? || block_given? - - limit(2).count > 1 - end - private # Get the finder used to generate the id query. diff --git a/lib/mongoid/findable.rb b/lib/mongoid/findable.rb index d3fb43abf6..5af578c0b5 100644 --- a/lib/mongoid/findable.rb +++ b/lib/mongoid/findable.rb @@ -17,7 +17,6 @@ module Findable # directly from the class level. def_delegators :with_default_scope, :aggregates, - :any?, :avg, :create_with, :distinct, @@ -119,6 +118,36 @@ def exists?(id_or_conditions = :none) with_default_scope.exists?(id_or_conditions) end + # Return true if any documents exist in the criteria. + # + # @example Determine if any documents exist + # criteria.any? + # + # @return [ true | false ] If any documents exist. + def any?(*args, &block) + limit(1).count > 0 + end + + # Return true if only one document exists in the criteria. + # + # @example Determine if only one document exists + # criteria.one? + # + # @return [ true | false ] If only one document exists. + def one?(*args, &block) + limit(2).count == 1 + end + + # Return true if more than one document exists in the criteria. + # + # @example Determine if many documents exist + # criteria.many? + # + # @return [ true | false ] If many documents exist. + def many?(*args, &block) + limit(2).count > 1 + end + # Finds a +Document+ or multiple documents by their _id values. # # If a single non-Array argument is given, this argument is interpreted From 377bbd59f53463e24c049e1a9107d0648ae80e77 Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 16:22:38 -0500 Subject: [PATCH 07/10] removing unneeded delegates --- lib/mongoid/findable.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/mongoid/findable.rb b/lib/mongoid/findable.rb index 5af578c0b5..9e37e9cb19 100644 --- a/lib/mongoid/findable.rb +++ b/lib/mongoid/findable.rb @@ -40,12 +40,10 @@ module Findable :fourth!, :includes, :last!, - :many?, :map_reduce, :max, :min, :none, - :one?, :pick, :pluck, :raw, From d7c52980cb50c821c809706ae5c9688f8b6cd58f Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 16:56:56 -0500 Subject: [PATCH 08/10] Moving tests to different file --- lib/mongoid/findable.rb | 12 +- spec/mongoid/criteria/findable_spec.rb | 195 ------------------------- spec/mongoid/findable_spec.rb | 83 +++++++++++ 3 files changed, 89 insertions(+), 201 deletions(-) diff --git a/lib/mongoid/findable.rb b/lib/mongoid/findable.rb index 9e37e9cb19..64dd5b818f 100644 --- a/lib/mongoid/findable.rb +++ b/lib/mongoid/findable.rb @@ -119,30 +119,30 @@ def exists?(id_or_conditions = :none) # Return true if any documents exist in the criteria. # # @example Determine if any documents exist - # criteria.any? + # Model.any? # # @return [ true | false ] If any documents exist. - def any?(*args, &block) + def any?() limit(1).count > 0 end # Return true if only one document exists in the criteria. # # @example Determine if only one document exists - # criteria.one? + # Model.one? # # @return [ true | false ] If only one document exists. - def one?(*args, &block) + def one?() limit(2).count == 1 end # Return true if more than one document exists in the criteria. # # @example Determine if many documents exist - # criteria.many? + # Model.many? # # @return [ true | false ] If many documents exist. - def many?(*args, &block) + def many?() limit(2).count > 1 end diff --git a/spec/mongoid/criteria/findable_spec.rb b/spec/mongoid/criteria/findable_spec.rb index 778af8fb4a..1468fc5f80 100644 --- a/spec/mongoid/criteria/findable_spec.rb +++ b/spec/mongoid/criteria/findable_spec.rb @@ -1302,201 +1302,6 @@ end end - describe "#any?" do - context "when called on criteria" do - let!(:band) do - Band.create!(name: "Depeche Mode") - end - - let!(:band_two) do - Band.create!(name: "Radiohead") - end - - context "when documents exist" do - - let(:criteria) do - Band.all - end - - it "returns true" do - expect(criteria.any?).to be true - end - end - - context "when no documents exist" do - - let(:criteria) do - Band.where(name: "Nonexistent Band") - end - - it "returns false" do - expect(criteria.any?).to be false - end - end - end - - context "when called on class" do - context "with documents" do - before do - Band.create!(name: "New Band") - end - - it "returns true" do - expect(Band.any?).to be true - end - end - - context "with no documents" do - it "returns false" do - expect(Band.any?).to be false - end - end - end - end - - describe "#one?" do - context "when called on criteria" do - let!(:band) do - Band.create!(name: "Depeche Mode") - end - - let!(:band_two) do - Band.create!(name: "Radiohead") - end - - context "when one document exists in criteria" do - let(:criteria) do - Band.where(name: "Depeche Mode") - end - - it "returns true" do - expect(criteria.one?).to be true - end - end - - context "when multiple documents exist in criteria" do - let(:criteria) do - Band.all - end - - it "returns false" do - expect(criteria.one?).to be false - end - end - - context "when no documents exist in criteria" do - let(:criteria) do - Band.where(name: "Nonexistent Band") - end - - it "returns false" do - expect(criteria.one?).to be false - end - end - end - - context "when called on class" do - context "with no documents" do - it "returns false" do - expect(Band.one?).to be false - end - end - - context "with one document" do - before do - Band.create!(name: "Another Band") - end - - it "returns true" do - expect(Band.one?).to be true - end - end - - context "with multiple documents" do - before do - Band.create!(name: "New Band") - Band.create!(name: "Yet Another Band") - end - - it "returns false" do - expect(Band.one?).to be false - end - end - end - end - - describe "#many?" do - context "when called on criteria" do - let!(:band) do - Band.create!(name: "Depeche Mode") - end - - let!(:band_two) do - Band.create!(name: "Radiohead") - end - - context "when multiple documents exist in criteria" do - let(:criteria) do - Band.all - end - - it "returns true" do - expect(criteria.many?).to be true - end - end - - context "when one document exists in criteria" do - let(:criteria) do - Band.where(name: "Depeche Mode") - end - - it "returns false" do - expect(criteria.many?).to be false - end - end - - context "when no documents exist in criteria" do - let(:criteria) do - Band.where(name: "Nonexistent Band") - end - - it "returns false" do - expect(criteria.many?).to be false - end - end - - end - - context "when called on class" do - context "with no documents" do - it "returns false" do - expect(Band.many?).to be false - end - end - - context "with one document" do - before do - Band.create!(name: "Another Band") - end - - it "returns false" do - expect(Band.many?).to be false - end - end - - context "with multiple documents" do - before do - Band.create!(name: "New Band") - Band.create!(name: "Yet Another Band") - end - - it "returns true" do - expect(Band.many?).to be true - end - end - end - end - describe '#from_database_selector' do let(:criteria) { Mongoid::Criteria.new(Band) } let(:result) { criteria.send(:from_database_selector, [1]) } diff --git a/spec/mongoid/findable_spec.rb b/spec/mongoid/findable_spec.rb index 8e01594410..d7eb2f8875 100644 --- a/spec/mongoid/findable_spec.rb +++ b/spec/mongoid/findable_spec.rb @@ -160,6 +160,89 @@ end end + describe "#any?" do + context "when called on class" do + context "with documents" do + before do + Band.create!(name: "Tool") + end + + it "returns true" do + expect(Band.any?).to be true + end + end + + context "with no documents" do + + it "returns false" do + expect(Band.any?).to be false + end + end + end + end + + describe "#one?" do + context "when called on class" do + context "with no documents" do + it "returns false" do + expect(Band.one?).to be false + end + end + + context "with one document" do + before do + Band.create!(name: "Radiohead") + end + + it "returns true" do + expect(Band.one?).to be true + end + end + + context "with multiple documents" do + before do + Band.create!(name: "Tool") + Band.create!(name: "Radiohead") + end + + it "returns false" do + expect(Band.one?).to be false + end + end + end + end + + describe "#many?" do + context "when called on class" do + context "with no documents" do + it "returns false" do + expect(Band.many?).to be false + end + end + + context "with one document" do + before do + Band.create!(name: "Radiohead") + end + + it "returns false" do + expect(Band.many?).to be false + end + end + + context "with multiple documents" do + before do + Band.create!(name: "Radiohead") + Band.create!(name: "Tool") + end + + it "returns true" do + expect(Band.many?).to be true + end + end + end + end + describe "find_by!" do context "when the document is found" do From b37cf865fd8c350003ef3e8e3e82e78775136545 Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Fri, 5 Dec 2025 16:58:26 -0500 Subject: [PATCH 09/10] removing extra nesting --- spec/mongoid/findable_spec.rb | 99 +++++++++++++++++------------------ 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/spec/mongoid/findable_spec.rb b/spec/mongoid/findable_spec.rb index d7eb2f8875..13d16c1534 100644 --- a/spec/mongoid/findable_spec.rb +++ b/spec/mongoid/findable_spec.rb @@ -161,84 +161,79 @@ end describe "#any?" do - context "when called on class" do - context "with documents" do - before do - Band.create!(name: "Tool") - end + context "when called on collection with documents" do + before do + Band.create!(name: "Tool") + end - it "returns true" do - expect(Band.any?).to be true - end + it "returns true" do + expect(Band.any?).to be true end + end - context "with no documents" do + context "when called on collection with no documents" do - it "returns false" do - expect(Band.any?).to be false - end + it "returns false" do + expect(Band.any?).to be false end end end describe "#one?" do - context "when called on class" do - context "with no documents" do - it "returns false" do - expect(Band.one?).to be false - end + context "when called on collection with no documents" do + it "returns false" do + expect(Band.one?).to be false end + end - context "with one document" do - before do - Band.create!(name: "Radiohead") - end + context "when called on collection with one document" do + before do + Band.create!(name: "Radiohead") + end - it "returns true" do - expect(Band.one?).to be true - end + it "returns true" do + expect(Band.one?).to be true end + end - context "with multiple documents" do - before do - Band.create!(name: "Tool") - Band.create!(name: "Radiohead") - end + context "when called on collection with multiple documents" do + before do + Band.create!(name: "Tool") + Band.create!(name: "Radiohead") + end - it "returns false" do - expect(Band.one?).to be false - end + it "returns false" do + expect(Band.one?).to be false end end + end describe "#many?" do - context "when called on class" do - context "with no documents" do - it "returns false" do - expect(Band.many?).to be false - end + context "when called on collection with no documents" do + it "returns false" do + expect(Band.many?).to be false end + end - context "with one document" do - before do - Band.create!(name: "Radiohead") - end + context "when called on collection with one document" do + before do + Band.create!(name: "Radiohead") + end - it "returns false" do - expect(Band.many?).to be false - end + it "returns false" do + expect(Band.many?).to be false end + end - context "with multiple documents" do - before do - Band.create!(name: "Radiohead") - Band.create!(name: "Tool") - end + context "when called on collection with multiple documents" do + before do + Band.create!(name: "Radiohead") + Band.create!(name: "Tool") + end - it "returns true" do - expect(Band.many?).to be true - end + it "returns true" do + expect(Band.many?).to be true end end end From 941699662c5a8be9080042cf1a07075435050ab9 Mon Sep 17 00:00:00 2001 From: Kyle Burgess Date: Mon, 8 Dec 2025 12:57:11 -0500 Subject: [PATCH 10/10] Removed unnecessary spacing and () --- lib/mongoid/findable.rb | 6 +++--- spec/mongoid/findable_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mongoid/findable.rb b/lib/mongoid/findable.rb index 64dd5b818f..3d34e1bacc 100644 --- a/lib/mongoid/findable.rb +++ b/lib/mongoid/findable.rb @@ -122,7 +122,7 @@ def exists?(id_or_conditions = :none) # Model.any? # # @return [ true | false ] If any documents exist. - def any?() + def any? limit(1).count > 0 end @@ -132,7 +132,7 @@ def any?() # Model.one? # # @return [ true | false ] If only one document exists. - def one?() + def one? limit(2).count == 1 end @@ -142,7 +142,7 @@ def one?() # Model.many? # # @return [ true | false ] If many documents exist. - def many?() + def many? limit(2).count > 1 end diff --git a/spec/mongoid/findable_spec.rb b/spec/mongoid/findable_spec.rb index 13d16c1534..aba2183285 100644 --- a/spec/mongoid/findable_spec.rb +++ b/spec/mongoid/findable_spec.rb @@ -1005,4 +1005,4 @@ expect(User.distinct(:name)).to match_array(['Tom']) end end -end +end \ No newline at end of file