-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Fix InheritanceTest#test_scope_inherited_properly implementation bugs #21994
Conversation
This triggers the JoinDependency work to reflect on the associations and trigger an error as follows: ActiveRecord::ConfigurationError: Association named 'account' was not found on Company; perhaps you misspelled it?
Should be `Company.joins(:accounts)` not `Company.joins(:account)`.
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @carlosantoniodasilva (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Hmm, would like to see mtodd@b780f95 built and fail as expected. |
@@ -13,7 +13,7 @@ class Company < AbstractCompany | |||
has_many :accounts | |||
|
|||
scope :of_first_firm, lambda { | |||
joins(:account => :firm). | |||
joins(:accounts => :firm). | |||
where('firms.id' => 1) | |||
} |
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.
Not sure if this was the original intent and a simple typo, or if the association for the has_one :account
is failing to be inherited.
assert_nothing_raised { Company.of_first_firm } | ||
assert_nothing_raised { Client.of_first_firm } | ||
assert_nothing_raised { Company.of_first_firm.to_sql } | ||
assert_nothing_raised { Client.of_first_firm.to_sql } |
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.
#21994 (comment) still applies (RE: JoinDependency
)
Fix InheritanceTest#test_scope_inherited_properly implementation bugs
thanks , merged via 60c9701 |
That broke the build so I reverted it. |
For the record: the failing build referenced includes https://travis-ci.org/rails/rails/jobs/87585808#L1309-L1309 @rafaelfranca @arthurnn looks like @rafaelfranca @arthurnn who would know best about the current implementation of scope inheritance and this test in particular? @sikachu backported @Ben-M's patch for this test a while back, though I'm not sure how much the implementation has changed or whether the test was failing correctly in the first place (before the fix was applied), if the association in In fact, I'm noticing that the Following that line of reasoning, it would seem that it doesn't matter if the association actually exists at all, just that both Am I understanding the situation correctly? Is this kind of test or test environment acceptable? If this is the case, I don't mind adding a comment in to explain as much for anybody who stumbles upon the test and wonders what the intent was, and offers a warning that the actual scope itself doesn't work. |
Opened #22084 with a simple documentation change, assuming I'm understanding the nature of the test correctly. |
I've updated the
InheritanceTest#test_scope_inherited_properly
test to trigger a reflection on the associations (whichActiveRecord::Relation
does lazily). This causes the following error to be raised, indicating the test is not properly testing scope inheritance:This PR fixes #21993 by fixing the pluralization of the
joins
clause on theCompany.of_first_firm
scope.Inheritance is indeed properly working, just improperly tested. 😄