Add and apply Rails/I18nLocaleAssignment rule
This rule was added in rubocop-rails 2.11.0. Although we prevent I18n locale leaking between tests by setting it before each test, the `with_locale` method makes the scope of the locale change more obvious.
This commit is contained in:
@@ -248,6 +248,11 @@ Rails/HasManyOrHasOneDependent:
|
||||
Rails/HttpStatus:
|
||||
Enabled: true
|
||||
|
||||
Rails/I18nLocaleAssignment:
|
||||
Enabled: true
|
||||
Exclude:
|
||||
- "spec/spec_helper.rb"
|
||||
|
||||
Rails/InverseOf:
|
||||
Enabled: true
|
||||
Exclude:
|
||||
|
||||
@@ -42,12 +42,13 @@ describe "I18n" do
|
||||
I18n.backend.store_translations(:zz, {})
|
||||
|
||||
I18n.enforce_available_locales = false
|
||||
I18n.locale = :zz
|
||||
I18n.fallbacks[:zz] << I18n.default_locale
|
||||
I18n.with_locale(:zz) do
|
||||
I18n.fallbacks[:zz] << I18n.default_locale
|
||||
|
||||
expect(I18n.t("test_plural", count: 0)).to eq("No comments")
|
||||
expect(I18n.t("test_plural", count: 1)).to eq("1 comment")
|
||||
expect(I18n.t("test_plural", count: 2)).to eq("2 comments")
|
||||
expect(I18n.t("test_plural", count: 0)).to eq("No comments")
|
||||
expect(I18n.t("test_plural", count: 1)).to eq("1 comment")
|
||||
expect(I18n.t("test_plural", count: 2)).to eq("2 comments")
|
||||
end
|
||||
end
|
||||
|
||||
it "returns count if specific plural rule not present" do
|
||||
|
||||
@@ -336,30 +336,34 @@ describe Budget do
|
||||
describe "#formatted_amount" do
|
||||
it "correctly formats Euros with Spanish" do
|
||||
budget.update!(currency_symbol: "€")
|
||||
I18n.locale = :es
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 €"
|
||||
I18n.with_locale(:es) do
|
||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 €"
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly formats Dollars with Spanish" do
|
||||
budget.update!(currency_symbol: "$")
|
||||
I18n.locale = :es
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 $"
|
||||
I18n.with_locale(:es) do
|
||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 $"
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly formats Dollars with English" do
|
||||
budget.update!(currency_symbol: "$")
|
||||
I18n.locale = :en
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "$1,000"
|
||||
I18n.with_locale(:en) do
|
||||
expect(budget.formatted_amount(1000.00)).to eq "$1,000"
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly formats Euros with English" do
|
||||
budget.update!(currency_symbol: "€")
|
||||
I18n.locale = :en
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "€1,000"
|
||||
I18n.with_locale(:en) do
|
||||
expect(budget.formatted_amount(1000.00)).to eq "€1,000"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -33,10 +33,11 @@ RSpec.describe Poll::Question, type: :model do
|
||||
end
|
||||
|
||||
context "locale with non-underscored name" do
|
||||
before { I18n.locale = :"pt-BR" }
|
||||
|
||||
it "correctly creates a translation" do
|
||||
poll_question.copy_attributes_from_proposal(proposal)
|
||||
I18n.with_locale(:"pt-BR") do
|
||||
poll_question.copy_attributes_from_proposal(proposal)
|
||||
end
|
||||
|
||||
translation = poll_question.translations.first
|
||||
|
||||
expect(poll_question.title).to eq(proposal.title)
|
||||
|
||||
Reference in New Issue
Block a user