Skip to content
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

CollectionProxy#include? returns true and false as documented. #10987

Merged
merged 1 commit into from Jun 18, 2013

Conversation

senny
Copy link
Member

@senny senny commented Jun 18, 2013

Closes #10979

The CollectionProxy#include? method is documented to return true but it can also return 1 and nil. I adjusted the tests and the implementation to make sure it returns booleans.

@senny
Copy link
Member Author

senny commented Jun 18, 2013

@fxn can you take a look?

@fxn
Copy link
Member

fxn commented Jun 18, 2013

Looks good to me. Do we really need a CHANGELOG? If someone reads the CHANGELOG he may think this is something new, if we are fixing a regression introduced sometime in the 4 branch I believe it is not needed.

@senny
Copy link
Member Author

senny commented Jun 18, 2013

@fxn agreed, entry is removed.

@fxn
Copy link
Member

fxn commented Jun 18, 2013

Awesome :).

fxn added a commit that referenced this pull request Jun 18, 2013
…s_true

`CollectionProxy#include?` returns `true` and `false` as documented.
@fxn fxn merged commit 7324624 into rails:master Jun 18, 2013
@senny senny deleted the 10979_association_include_returns_true branch June 18, 2013 07:01
@@ -830,7 +830,7 @@ def many?(&block)
# person.pets.include?(Pet.find(20)) # => true
# person.pets.include?(Pet.find(21)) # => false
def include?(record)
@association.include?(record)
!!@association.include?(record)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering why would underlying @association's .include? not return a boolean in the first place? If it behaved like Ruby array/enum, it would be boolean whether true or false. Should the change instead live in @association?

Copy link
Member

Choose a reason for hiding this comment

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

Not really in my view. The wrapped predicate is not even documented, and there is no reason it should return anything in particular, you only need to know it behaves as a predicate. On the other hand the method patched here is public, he is the one responsible for his contract.

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.

include? in ActiveRecord::Associations::CollectionProxy return 1 instead of true
3 participants