-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
order of acts_as_tenant declaration subverts validation errors and save exceptions when associated tenants do not match #255
Comments
This test mimics acts_as_tenant:/spec/models/model_extensions.rb:194, 'associations can only be made with in-scope objects'. See ErwinM/acts_as_tenant#255.
Here is another test. It mimics acts_as_tenant:/spec/models/model_extensions.rb:194, "associations can only be made with in-scope:objects". https://github.com/ybakos/acts_as_tenant_issue_tests/blob/main/test/models/account_test.rb
Am I losing my mind or is there indeed a problem? This is a Rails 6.1.3 app. I've run the rspec suite for acts_as_tenant and the behavior there within its "dummy" app is as expected. But I am seeing unexpected association behavior in both this example 6.1.3 app and a 5.2.4 app. |
The tests were failing, and they should have been passing. Now watch this: move the acts_as_tenant declaration after the other associations declarations. The tests now pass. See ErwinM/acts_as_tenant#255.
The tests were failing, and they should have been passing. Now watch this: move the acts_as_tenant declaration after the other associations declarations. The tests now pass. See ErwinM/acts_as_tenant#255.
Aha, found the issue. Is this a bug or did I miss the instructions that state "one must declare acts_as_tenant after all other associations" ? |
^^^ That was not a smart alec comment, I truly wondered if the doc emphasized that or not. I just checked... and although it does mention the order concern in the controller for setting the tenant, there is no mention of the order concern at the model layer. Indeed, if I switch the declaration of Task to:
and also in Project:
We see the test error:
|
When acts_as_tenant comes before other associations, it does not seem to properly check the tenant when associating model instances with eachother. (WTF) I debugged this for hours. See ErwinM/acts_as_tenant#255. References #163.
Via #11 .
I believe there may be some inconsistency to how well acts_as_tenant may be emitting validation errors or raising exceptions when saving a model with associations referring to other tenants.
Should acts_as_tenant be properly ensuring that models within a chain of associations are all of the same tenant? For example, given C belongs to B, and both B and C belong to Account via acts_as_tenant, shouldn't the gem enforce that C and B's accounts are the same?
It appears it does not.
Here's a barebones Rails 6.1.3 repo using acts_as_tenant 0.5.0: https://github.com/ybakos/acts_as_tenant_issue_tests
Notice the contents of test/models/person_test.rb
This surprised me, because in the past I have indeed see act_as_tenant emit some appropriate errors when the tenants do not match.
The text was updated successfully, but these errors were encountered: