-
Notifications
You must be signed in to change notification settings - Fork 123
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
switch from creating new organization to setting organization to tenant #491
switch from creating new organization to setting organization to tenant #491
Conversation
I assume this has to do with ActsAsTenant scoping behavior. I think your solution is good, as I think creating an organization in individual tests generally should not be done. The test_helper setup makes an organization already and sets up that organization as the I assume that is why removing the setup fixes the error in your investigation because then I presume ActsAsTenant does not have a I am having trouble replicating this flaky test to investigate further. I do think I noticed this test fail once before, but I have a shell running all tests in a loop right now and can't seem to replicate a failure. Do you happen to know how I could reliably replicate the failure? |
I commented too soon! Got an error in my shell loop. Actually, there is a chance this may not even be related to ActsAsTenant. I still think your solution is worth pushing though. I noticed in the failure, that the @organization.profile was not valid: (ruby@bin/rails#31838) @organization
#<Organization:0x000000010ed8e118
id: 6878,
name: "Marvin, Berge and Kautzer",
created_at: Sun, 03 Mar 2024 04:13:41.115549000 UTC +00:00,
updated_at: Sun, 03 Mar 2024 04:13:41.115549000 UTC +00:00,
slug: "weimann2">
(ruby@bin/rails#31838) ActsAsTenant.current_tenant
#<Organization:0x000000010ea5fbb8
id: 6877,
name: "Carroll Group",
created_at: Sun, 03 Mar 2024 04:13:41.103760000 UTC +00:00,
updated_at: Sun, 03 Mar 2024 04:13:41.103760000 UTC +00:00,
slug: "test">
(ruby@bin/rails#31838) @organization.location
nil
(ruby@bin/rails#31838) @organization.profile.location
#<Location:0x000000010ef0f7d0
id: 7605,
country: "Country27",
city_town: "Thompsonchester",
province_state: "Delaware",
created_at: Sun, 03 Mar 2024 04:13:41.110607000 UTC +00:00,
updated_at: Sun, 03 Mar 2024 04:13:41.110607000 UTC +00:00,
zipcode: "02401-9622">
(ruby@bin/rails#31838) @organization.profile.location.valid?
true
(ruby@bin/rails#31838) @organization.profile.valid?
false
(ruby@bin/rails#31838) @organization.profile.errors.full_messages
["Phone number Phone Number is invalid"] It looks like the reason |
Did a bit more investigating... And I'm also seeing that the phone number is the culprit. It looks like the invalid phone numbers are failing the check for |
Ok this has reminded be of some weird stuff happening on OrganizationProfile
|
@kasugaijin This is both fascinating and bizarre. In the Rails console, I get the same things |
hmmm I bet Phonelib documentation and/or issues will have an explanation for this. It must be something that has come up before :) |
Interesting...so I wonder why it will format '1234567891' with a '+' which will subsequently fail? Maybe because it is not a real number (area code) and cannot find the country? I think that's what you're saying? If I enter my 10 digit number without country, it saves and then formats it with '+1' which saves the second time, probably because it finds a country based on area code. So, I think we can use a real number in the seeds...or at least one with a real area code and prefix https://linkedphone.com/blog/what-are-the-different-parts-of-a-phone-number-called/ |
@kasugaijin It might not be that sophisticated. It might just be a problem that the number started with a 1. It could be that the methods used to normalize the phone number won't add the additional 1 if the number starts with a 1 already. |
Ah yes that makes sense thank you @MooseCowBear . I think we have learned something about making valid seed data here! So is this PR still needed given #492 |
@kasugaijin There's still the mystery of why creating a new organization in the test setup would sometimes create phone numbers that fail but the tenant somehow doesn't. We could just change the organization profile factory to set the phone number to a string not starting with a 1 instead of using Faker::PhoneNumber which we can't control instead of the change made in this PR. |
Yes let's do that. I cannot be sure the Faker numbers never start with a 1 (have not looked into it), but hard coding a string that we know will satisfy seems like an easy, reliable approach. @MooseCowBear |
🔗 Issue
Fix for flaky
HomeControllerTest
(hopefully).✍️ Description
Creating a new organization for the test using the factory led to
@organization.location
occasionally coming up nil. Switching to using the tenant seems to resolve that (ran a few hundred trials without failure).As for why...
This part is sort of baffling to me because the factory for organization called in the setup block always created a profile and the profile factory always created a location, and the location was always accessible with
@organization.profile.location
but not always with@organization.location
.It seems that something about setting the tenant in the test helper setup block interferes when generating the organization with a factory because an alternative way that also seems to resolve the issue (at least for a few hundred trials) is to remove the setup block in test helper.
📷 Screenshots/Demos