-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 flaky spec: Budget Investments Show milestones #2719
Fix flaky spec: Budget Investments Show milestones #2719
Conversation
The test "Budget Investments Show milestones" was failing in certain cases where `Globalize.locale` had been changed in a previous test. Since having different values in `Globalize.locale` and `I18n.locale` has proven to be an issue on the test enviroment, this commit also changes application code in order to avoid similar situations on production. See issue consuldemocracy#2718.
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.
Hello again @javierv !
For this PR, I'll only leave one comment as it's a pretty short patch.
I know you mentioned on the Notes
section this is not necessary to get the test green but I'd like some in-depth details on why do you think the actual code can cause problems on a production environment
Thanks a lot once again. We appreciate your constant collaboration with CONSUL ❤️
@@ -2,7 +2,6 @@ module Translatable | |||
extend ActiveSupport::Concern | |||
|
|||
included do | |||
before_action :set_translation_locale |
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.
What will happen if we don't delete this callback? (as well as its related method)
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.
With these changes, this callback would be redundant, since the same thing is now done in ApplicationController
.
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.
You mean ApplicationController#set_locale
does the exact same thing as Translatable#set_translation_locale
(?)
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.
Before these changes, ApplicationController#set_locale
configured I18n.locale
and Translatable#set_translation_locale
configured Globalize.locale
.
After these changes, ApplicationController#set_locale
configures both I18n.locale
and Globalize.locale
. So there's no need for Translatable#set_translation_locale
anymore, since Globalize.locale
is already configured.
At least that's what I think 😅.
@aitbw Funny thing: I don't think the code can cause problems on production. But I didn't think it could cause problems while testing, and it did, so I don't trust myself that much 😆. Without these changes, on production there are moments where However, I see an advantage while developing, particularly for developers who aren't so familiar with the code like myself. Setting Needless to say, I'm not familiar enough with CONSUL to be sure one option is better than the other one, so whatever you think is fine for me 👍! |
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.
Looks good to me 👌
References
Objectives
Fix the flaky spec that appeared in
spec/features/budgets/investments_spec.rb:994
("Budget Investments Show milestones").Explain why the test is flaky, or under which conditions/scenario it fails randomly
The test fails if
Globalize.locale != I18n.locale
when the test starts. AFAIK there's only one test which can modify that locale:spec/features/translations_spec.rb:76
("Translations Milestones Globalize javascript interface Highlight current locale"). So, to reproduce it locally, run those tests making sure the translations test runs first. On my machine, this command makes the test fail every time:bin/rspec spec/features/budgets/investments_spec.rb:994 spec/features/translations_spec.rb:76 --seed 6700
Here's what happens during those two tests:
Globalize.locale = :es
.config.before
block setsI18n.locale = :en
first_milestone
, which will get assigneddescription_es
(as set by Globalize).visit budget_investment_path
renders the milestones, which include the lineglobalize(neutral_locale(locale))
.locale
isI18n.locale
(that is,:en
), the block will callfirst_milestone.description_en
, which will returnnil
.nil
instead.Explain why your PR fixes it
By setting
Globalize.locale = I18n.locale
before each test, the changes one test might cause don't affect any other test.Notes
ApplicationController
andManagement::BaseController
isn't necessary to make the test pass. However, since having different values inGlobalize.locale
andI18n.locale
has proven to be an issue on the test enviroment, I've also changed application code in order to avoid similar situations on production. Different opinions are welcome!