Skip to content

Conversation

@kyleburgess2025
Copy link

This PR adds the enumerable methods any, many, and one to the Criteria class. It also delegates calls to these functions at the class level to the methods defined on Criteria. For example, User.any? should return if any documents exist in the users table.

end
end

context "when called on class" do
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if this needs to be moved elsewhere or isnt needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should probably be moved to spec/mongoid/findable_spec.rb, since it's no longer implemented on Mongoid::Criteria.

When you move these, you should also make sure the tests invoke the new methods directly on the model classes, rather than on criteria instances. E.g.

let(:model) { Band } # instance of :criteria

# ...

expect(model.any?).to be true

# criteria.any?
#
# @return [ true | false ] If any documents exist.
def any?(*args, &block)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to leave off the *args and &block here, since they aren't used in the method body anymore.

Ditto for the other two methods you added. 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

# Return true if any documents exist in the criteria.
#
# @example Determine if any documents exist
# criteria.any?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is an artifact from when you had this on Mongoid::Criteria, but for documentation purposes you can just reference Model, generically.

Suggested change
# criteria.any?
# Model.any?

Ditto for the other new methods you added.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

end
end

context "when called on class" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this should probably be moved to spec/mongoid/findable_spec.rb, since it's no longer implemented on Mongoid::Criteria.

When you move these, you should also make sure the tests invoke the new methods directly on the model classes, rather than on criteria instances. E.g.

let(:model) { Band } # instance of :criteria

# ...

expect(model.any?).to be true

@kyleburgess2025 kyleburgess2025 requested a review from jamis December 5, 2025 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants