Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rails/I18nLocaleAssignment cop #24693

Merged
merged 1 commit into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1335,14 +1335,6 @@ Rails/HasManyOrHasOneDependent:
- 'app/models/user.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:
Exclude:
- 'lib/tasks/mastodon.rake'
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/auth/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
end

around do |example|
current_locale = I18n.locale
example.run
I18n.locale = current_locale
I18n.with_locale(I18n.locale) do
example.run
end
end

before { request.env['devise.mapping'] = Devise.mappings[:user] }
Expand Down
26 changes: 12 additions & 14 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,28 @@
end

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
I18n.locale = :ar
expect(helper.locale_direction).to eq 'rtl'
I18n.with_locale(:ar) do
expect(helper.locale_direction).to eq 'rtl'
end
end

it 'adds rtl body class if locale is Farsi' do
I18n.locale = :fa
expect(helper.locale_direction).to eq 'rtl'
I18n.with_locale(:fa) do
expect(helper.locale_direction).to eq 'rtl'
end
end

it 'adds rtl if locale is Hebrew' do
I18n.locale = :he
expect(helper.locale_direction).to eq 'rtl'
I18n.with_locale(:he) do
expect(helper.locale_direction).to eq 'rtl'
end
end

it 'does not add rtl if locale is Thai' do
I18n.locale = :th
expect(helper.locale_direction).to_not eq 'rtl'
I18n.with_locale(:th) do
expect(helper.locale_direction).to_not eq 'rtl'
end
end
end

Expand Down
6 changes: 4 additions & 2 deletions spec/requests/localization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
require 'rails_helper'

describe 'Localization' do
after(:all) do
I18n.locale = I18n.default_locale
around do |example|
I18n.with_locale(I18n.locale) do
example.run
end
end

it 'uses a specific region when provided' do
Expand Down