From 51d760960ccf0866eba32944434ba08b2cbe5092 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Sun, 4 Mar 2018 17:21:35 +0900 Subject: Set the default locale in config (#6580) Previously the default locale was set by Localized concern for controllers, but it was not enforced for mailers. config is enforced throughout the application and an appropriate place to set the default locale. --- spec/controllers/concerns/localized_spec.rb | 53 ++++++++--------------------- 1 file changed, 14 insertions(+), 39 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/concerns/localized_spec.rb b/spec/controllers/concerns/localized_spec.rb index c917ce85e..f71c96aff 100644 --- a/spec/controllers/concerns/localized_spec.rb +++ b/spec/controllers/concerns/localized_spec.rb @@ -16,49 +16,24 @@ describe ApplicationController, type: :controller do end shared_examples 'default locale' do - context 'when DEFAULT_LOCALE environment variable is set' do - around do |example| - ClimateControl.modify 'DEFAULT_LOCALE' => 'ca', &example.method(:run) - I18n.locale = I18n.default_locale - end + after { I18n.locale = I18n.default_locale } - it 'sets language specified by ENV if preferred' do - request.headers['Accept-Language'] = 'ca, fa' - get 'success' - expect(I18n.locale).to eq :ca - end - - it 'sets available and preferred language if language specified by ENV is not preferred' do - request.headers['Accept-Language'] = 'ca-ES, fa' - get 'success' - expect(I18n.locale).to eq :fa - end - - it 'sets language specified by ENV if it is compatible and none of available languages are preferred' do - request.headers['Accept-Language'] = 'ca-ES, fa-IR' - get 'success' - expect(I18n.locale).to eq :ca - end - - it 'sets available and compatible langauge if language specified by ENV is not compatible none of available languages are preferred' do - request.headers['Accept-Language'] = 'fa-IR' - get 'success' - expect(I18n.locale).to eq :fa - end + it 'sets available and preferred language' do + request.headers['Accept-Language'] = 'ca-ES, fa' + get 'success' + expect(I18n.locale).to eq :fa + end - it 'sets language specified by ENV if none of available languages are compatible' do - request.headers['Accept-Language'] = '' - get 'success' - expect(I18n.locale).to eq :ca - end + it 'sets available and compatible langauge if none of available languages are preferred' do + request.headers['Accept-Language'] = 'fa-IR' + get 'success' + expect(I18n.locale).to eq :fa end - context 'when DEFAULT_LOCALE environment variable is not set' do - it 'sets default locale if none of available languages are compatible' do - request.headers['Accept-Language'] = '' - get 'success' - expect(I18n.locale).to eq :en - end + it 'sets default locale if none of available languages are compatible' do + request.headers['Accept-Language'] = '' + get 'success' + expect(I18n.locale).to eq :en end end -- cgit