-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MONGOID-5105: Mongoid::Association::EmbedsMany::Proxy#count should allow block form #5000
MONGOID-5105: Mongoid::Association::EmbedsMany::Proxy#count should allow block form #5000
Conversation
…count to make it congruent with #any?, #none?, #all?, etc. Example: Person.addresses.count {|a| a.country == "FR" } I've also added additional tests for other methods.
Nice PR number. |
Haha I was wondering if you'd notice that! |
Can this be merged? |
Hi @johnnyshields, Could you please merge the current master into your branch? I see there are test failures on evergreen, some of them should be fixed by merging the current master. I will check others then. Thank you! |
…-proxy-count-block
@comandeo done |
@johnnyshields Unfortunately, tests for this PR fail on Ruby 2.3 and 2.4:
Mongoid still supports 2.3 and 2.4 even in the latest version - https://docs.mongodb.com/mongoid/master/reference/compatibility/#ruby-compatibility |
@comandeo thanks. The correct solution here is just to ignore those tests on older Ruby. The mongoid code calls |
@comandeo may I ask why the CI is still failing? |
@johnnyshields CI is pretty green now, actually. The only configuration that fails is jruby-app-test; however, this configuration fails everywhere last couple of days. I created a ticked to investigate - https://jira.mongodb.org/browse/MONGOID-5134 - and disabled this configuration temporarily. So, if you merge the current master into your branch, everything should pass. |
…-proxy-count-block
OK done |
Now Ruby 3.0 failing? |
Actually, not, everything pass. There was a problem with a runner, some connectivity issues. Now all good. |
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 believe the behavior of Mongoid on all supported Ruby versions should be the same, if practical. I believe this generally how Rails works.
Therefore I believe either this PR would need to implement the missing block form behavior on Ruby 2.3 and 2.4, or Mongoid should increase the minimum required version to 2.5 at which point the 2.5+ checks in this PR would be unneeded.
In mongodb/mongo-ruby-driver#2298 we increased the minimum Ruby version to 2.4 for the driver, but per the docs in https://docs.mongodb.com/mongoid/master/reference/compatibility/#ruby-compatibility 2.3 and 2.4 support has already been deprecated for two Mongoid releases and perhaps the minimum can be increased to 2.5 to save work in this PR.
The behavior on all versions is the same: we delegate Regardless, Ruby 2.3 and 2.4 are both EOL (2019-03-31 and 2020-03-31). |
No patching of standard library methods is needed, the needed code can be added to Mongoid methods based on active Ruby version. |
I'm not going to add EOL Ruby 2.3 and 2.4 specific hacks in the Mongoid codebase. If any user wishes to emulate Ruby 2.5+ kernel behavior in Ruby 2.3/2.4, they are free to add such patches into their own project. |
- Update docs
Shall we merge this? If Mongoid team would like to add the EOL Ruby hacks it can be done as a separate PR; be aware they would apply to many methods ( |
I am confused how the build is green but more work is required to get this PR merged? |
@comandeo looks like this needs your review? |
Ruby 2.5 is now the min version, so the issues raised around Ruby 2.3/2.4 are no longer a concern. |
Closing in favor of #5060 |
Fixes MONGOID-5105
Mongoid::Association::EmbedsMany::Proxy#count
should allow block form to make it congruent with #any?, #none?, #all?, etc.Interestingly this already works for normal relations but not embedded ones.
Example:
To fully be congruent with the
method_missing
behavior, I've also added support for theargs
form of#count
, although it's not super useful in practice:I've also added additional tests for other methods
#any?
,#none?
,#all?
One of the reasons for doing this is that Rubocop/Performance corrects the following:
So this will help avoid accidental errors.