mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
12332 - Fix rubocop Rails/I18nLocaleAssignment errors
- use I18n.with_locale method rather than direct locale assignment
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user