Fix Rails/I18nLocaleAssignment cop (#24693)

shrike
Matt Jankowski 2023-04-30 08:07:03 -04:00 committed by GitHub
parent af824db398
commit d00e45a7d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 27 deletions

View File

@ -1335,14 +1335,6 @@ Rails/HasManyOrHasOneDependent:
- 'app/models/user.rb' - 'app/models/user.rb'
- 'app/models/web/push_subscription.rb' - 'app/models/web/push_subscription.rb'
# Configuration parameters: Include.
# Include: spec/**/*.rb, test/**/*.rb
Rails/I18nLocaleAssignment:
Exclude:
- 'spec/controllers/auth/registrations_controller_spec.rb'
- 'spec/helpers/application_helper_spec.rb'
- 'spec/requests/localization_spec.rb'
Rails/I18nLocaleTexts: Rails/I18nLocaleTexts:
Exclude: Exclude:
- 'lib/tasks/mastodon.rake' - 'lib/tasks/mastodon.rake'

View File

@ -104,9 +104,9 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end end
around do |example| around do |example|
current_locale = I18n.locale I18n.with_locale(I18n.locale) do
example.run example.run
I18n.locale = current_locale end
end end
before { request.env['devise.mapping'] = Devise.mappings[:user] } before { request.env['devise.mapping'] = Devise.mappings[:user] }

View File

@ -44,32 +44,30 @@ describe ApplicationHelper do
end end
describe 'locale_direction' do describe 'locale_direction' do
around do |example|
current_locale = I18n.locale
example.run
I18n.locale = current_locale
end
it 'adds rtl body class if locale is Arabic' do it 'adds rtl body class if locale is Arabic' do
I18n.locale = :ar I18n.with_locale(:ar) do
expect(helper.locale_direction).to eq 'rtl' expect(helper.locale_direction).to eq 'rtl'
end end
end
it 'adds rtl body class if locale is Farsi' do it 'adds rtl body class if locale is Farsi' do
I18n.locale = :fa I18n.with_locale(:fa) do
expect(helper.locale_direction).to eq 'rtl' expect(helper.locale_direction).to eq 'rtl'
end end
end
it 'adds rtl if locale is Hebrew' do it 'adds rtl if locale is Hebrew' do
I18n.locale = :he I18n.with_locale(:he) do
expect(helper.locale_direction).to eq 'rtl' expect(helper.locale_direction).to eq 'rtl'
end end
end
it 'does not add rtl if locale is Thai' do it 'does not add rtl if locale is Thai' do
I18n.locale = :th I18n.with_locale(:th) do
expect(helper.locale_direction).to_not eq 'rtl' expect(helper.locale_direction).to_not eq 'rtl'
end end
end end
end
describe 'fa_icon' do describe 'fa_icon' do
it 'returns a tag of fixed-width cog' do it 'returns a tag of fixed-width cog' do

View File

@ -3,8 +3,10 @@
require 'rails_helper' require 'rails_helper'
describe 'Localization' do describe 'Localization' do
after(:all) do around do |example|
I18n.locale = I18n.default_locale I18n.with_locale(I18n.locale) do
example.run
end
end end
it 'uses a specific region when provided' do it 'uses a specific region when provided' do