12332 - Fix rubocop Rails/I18nLocaleAssignment errors

- use I18n.with_locale method rather than direct locale assignment
This commit is contained in:
Ahmed Ejaz
2024-04-07 00:17:21 +05:00
committed by Maikel Linke
parent 89033579bd
commit 693b9bd171
5 changed files with 28 additions and 36 deletions

View File

@@ -51,12 +51,13 @@ describe UserRegistrationsController, type: :controller do
original_i18n_locale = I18n.locale
original_locale_cookie = cookies[:locale]
cookies[:locale] = "pt"
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
expect(assigns[:user].locale).to eq("pt")
I18n.locale = original_i18n_locale
cookies[:locale] = original_locale_cookie
# changes to +I18n.locale+ will only persist within the +with_locale+ block
I18n.with_locale(original_i18n_locale) do
cookies[:locale] = "pt"
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
expect(assigns[:user].locale).to eq("pt")
cookies[:locale] = original_locale_cookie
end
end
end
end