Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use I18n.with_locale in code to force load locale in test

Christophe Bliard21b487a49dde
diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb
index 492e816dffa..f51dcc911f9 100644
--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb
+++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb
@@ -159,11 +159,13 @@ module OpenProject::TwoFactorAuthentication
pause = '<break time="500ms"/>'
end
- I18n.t "two_factor_authentication.text_otp_delivery_message_#{channel}",
- pause:,
- token: token_value,
- app_title: Setting.app_title, locale: locale_key,
- fallback:, raise: raise_on_missing
+ I18n.with_locale(locale_key) do
+ I18n.t "two_factor_authentication.text_otp_delivery_message_#{channel}",
+ pause:,
+ token: token_value,
+ app_title: Setting.app_title,
+ fallback:, raise: raise_on_missing
+ end
end
##
diff --git a/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb
index 594071b025e..30ad8bd6d94 100644
--- a/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb
+++ b/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb
@@ -126,10 +126,6 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::MessageBird do
let(:expected_language) { :'en-us' }
before do
- I18n.with_locale(locale) do
- # Force loading of locale which are not all loaded in tests
- end
-
allow(subject.strategy)
.to receive(:has_localized_text?)
.with(locale)