-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MONGOID-5910 Implement enumerable methods on top level models (any?, many?, and one?) #6069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| end | ||
| end | ||
|
|
||
| context "when called on class" do |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
lib/mongoid/findable.rb
Outdated
| # criteria.any? | ||
| # | ||
| # @return [ true | false ] If any documents exist. | ||
| def any?(*args, &block) |
There was a problem hiding this comment.
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. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
lib/mongoid/findable.rb
Outdated
| # Return true if any documents exist in the criteria. | ||
| # | ||
| # @example Determine if any documents exist | ||
| # criteria.any? |
There was a problem hiding this comment.
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.
| # criteria.any? | |
| # Model.any? |
Ditto for the other new methods you added.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
This PR adds the enumerable methods
any,many, andoneto theCriteriaclass. It also delegates calls to these functions at the class level to the methods defined onCriteria. For example,User.any?should return if any documents exist in theuserstable.