diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f0bc6f67b5..52b702e701 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -576,16 +576,6 @@ Rails/HasManyOrHasOneDependent: - 'app/models/spree/tax_rate.rb' - 'app/models/spree/variant.rb' -# Offense count: 8 -# Configuration parameters: Include. -# Include: spec/**/*.rb, test/**/*.rb -Rails/I18nLocaleAssignment: - Exclude: - - 'spec/controllers/user_registrations_controller_spec.rb' - - 'spec/helpers/i18n_helper_spec.rb' - - 'spec/models/spree/variant_spec.rb' - - 'spec/system/admin/order_cycles/list_spec.rb' - # Offense count: 3 Rails/I18nLocaleTexts: Exclude: diff --git a/spec/controllers/user_registrations_controller_spec.rb b/spec/controllers/user_registrations_controller_spec.rb index 8d91a8d25f..fb948cfa4e 100644 --- a/spec/controllers/user_registrations_controller_spec.rb +++ b/spec/controllers/user_registrations_controller_spec.rb @@ -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 diff --git a/spec/helpers/i18n_helper_spec.rb b/spec/helpers/i18n_helper_spec.rb index c91b22f6af..546719180e 100644 --- a/spec/helpers/i18n_helper_spec.rb +++ b/spec/helpers/i18n_helper_spec.rb @@ -15,9 +15,10 @@ describe I18nHelper, type: :helper do # have to restore I18n.locale for unit tests that don't call the helper, but # rely on translated strings. around do |example| - locale = I18n.locale - example.run - I18n.locale = locale + original_locale = I18n.locale + I18n.with_locale(original_locale) do + example.run + end end context "as guest" do diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index aec627bf71..0de7418b8f 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -60,14 +60,12 @@ describe Spree::Variant do context "price parsing" do before(:each) do - I18n.locale = I18n.default_locale - I18n.backend.store_translations(:de, - { number: { currency: { format: { delimiter: '.', - separator: ',' } } } }) - end - - after do - I18n.locale = I18n.default_locale + default_locale = I18n.default_locale + I18n.with_locale(default_locale) do + I18n.backend.store_translations(:de, + { number: { currency: { format: { delimiter: '.', + separator: ',' } } } }) + end end context "price=" do @@ -80,17 +78,19 @@ describe Spree::Variant do context "with decimal comma" do it "captures the proper amount for a formatted price" do - I18n.locale = :es - variant.price = '1.599,99' - expect(variant.price).to eq 1599.99 + I18n.with_locale(:es) do + variant.price = '1.599,99' + expect(variant.price).to eq 1599.99 + end end end context "with a numeric price" do it "uses the price as is" do - I18n.locale = :es - variant.price = 1599.99 - expect(variant.price).to eq 1599.99 + I18n.with_locale(:es) do + variant.price = 1599.99 + expect(variant.price).to eq 1599.99 + end end end end diff --git a/spec/system/admin/order_cycles/list_spec.rb b/spec/system/admin/order_cycles/list_spec.rb index bcc977e5f8..87cef27c14 100644 --- a/spec/system/admin/order_cycles/list_spec.rb +++ b/spec/system/admin/order_cycles/list_spec.rb @@ -133,9 +133,9 @@ describe ' } around(:each) do |spec| - I18n.locale = :pt - spec.run - I18n.locale = :en + I18n.with_locale(:pt) do + spec.run + end end context 'using datetimepickers' do