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:
|
Rails/HttpStatus:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Rails/I18nLocaleAssignment:
|
||||||
|
Enabled: true
|
||||||
|
Exclude:
|
||||||
|
- "spec/spec_helper.rb"
|
||||||
|
|
||||||
Rails/InverseOf:
|
Rails/InverseOf:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Exclude:
|
Exclude:
|
||||||
|
|||||||
@@ -42,13 +42,14 @@ describe "I18n" do
|
|||||||
I18n.backend.store_translations(:zz, {})
|
I18n.backend.store_translations(:zz, {})
|
||||||
|
|
||||||
I18n.enforce_available_locales = false
|
I18n.enforce_available_locales = false
|
||||||
I18n.locale = :zz
|
I18n.with_locale(:zz) do
|
||||||
I18n.fallbacks[:zz] << I18n.default_locale
|
I18n.fallbacks[:zz] << I18n.default_locale
|
||||||
|
|
||||||
expect(I18n.t("test_plural", count: 0)).to eq("No 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: 1)).to eq("1 comment")
|
||||||
expect(I18n.t("test_plural", count: 2)).to eq("2 comments")
|
expect(I18n.t("test_plural", count: 2)).to eq("2 comments")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "returns count if specific plural rule not present" do
|
it "returns count if specific plural rule not present" do
|
||||||
keys = { zero: "No comments" }
|
keys = { zero: "No comments" }
|
||||||
|
|||||||
@@ -336,32 +336,36 @@ describe Budget do
|
|||||||
describe "#formatted_amount" do
|
describe "#formatted_amount" do
|
||||||
it "correctly formats Euros with Spanish" do
|
it "correctly formats Euros with Spanish" do
|
||||||
budget.update!(currency_symbol: "€")
|
budget.update!(currency_symbol: "€")
|
||||||
I18n.locale = :es
|
|
||||||
|
|
||||||
|
I18n.with_locale(:es) do
|
||||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 €"
|
expect(budget.formatted_amount(1000.00)).to eq "1.000 €"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "correctly formats Dollars with Spanish" do
|
it "correctly formats Dollars with Spanish" do
|
||||||
budget.update!(currency_symbol: "$")
|
budget.update!(currency_symbol: "$")
|
||||||
I18n.locale = :es
|
|
||||||
|
|
||||||
|
I18n.with_locale(:es) do
|
||||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 $"
|
expect(budget.formatted_amount(1000.00)).to eq "1.000 $"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "correctly formats Dollars with English" do
|
it "correctly formats Dollars with English" do
|
||||||
budget.update!(currency_symbol: "$")
|
budget.update!(currency_symbol: "$")
|
||||||
I18n.locale = :en
|
|
||||||
|
|
||||||
|
I18n.with_locale(:en) do
|
||||||
expect(budget.formatted_amount(1000.00)).to eq "$1,000"
|
expect(budget.formatted_amount(1000.00)).to eq "$1,000"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "correctly formats Euros with English" do
|
it "correctly formats Euros with English" do
|
||||||
budget.update!(currency_symbol: "€")
|
budget.update!(currency_symbol: "€")
|
||||||
I18n.locale = :en
|
|
||||||
|
|
||||||
|
I18n.with_locale(:en) do
|
||||||
expect(budget.formatted_amount(1000.00)).to eq "€1,000"
|
expect(budget.formatted_amount(1000.00)).to eq "€1,000"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#investments_milestone_tags" do
|
describe "#investments_milestone_tags" do
|
||||||
let(:investment1) { build(:budget_investment, :winner) }
|
let(:investment1) { build(:budget_investment, :winner) }
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ RSpec.describe Poll::Question, type: :model do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "locale with non-underscored name" do
|
context "locale with non-underscored name" do
|
||||||
before { I18n.locale = :"pt-BR" }
|
|
||||||
|
|
||||||
it "correctly creates a translation" do
|
it "correctly creates a translation" do
|
||||||
|
I18n.with_locale(:"pt-BR") do
|
||||||
poll_question.copy_attributes_from_proposal(proposal)
|
poll_question.copy_attributes_from_proposal(proposal)
|
||||||
|
end
|
||||||
|
|
||||||
translation = poll_question.translations.first
|
translation = poll_question.translations.first
|
||||||
|
|
||||||
expect(poll_question.title).to eq(proposal.title)
|
expect(poll_question.title).to eq(proposal.title)
|
||||||
|
|||||||
Reference in New Issue
Block a user