Refactor locale with around method
This commit is contained in:
@ -59,6 +59,8 @@ describe ApplicationController do
|
||||
context "with a 'locale' value in the session" do
|
||||
it 'sets this locale' do
|
||||
session[:locale] = locale
|
||||
# The around block first sets the default language and then the language requested
|
||||
expect(I18n).to receive(:locale=).with(I18n.default_locale)
|
||||
expect(I18n).to receive(:locale=).with(locale)
|
||||
get :welcome
|
||||
end
|
||||
@ -67,7 +69,7 @@ describe ApplicationController do
|
||||
context "without a 'locale' value in the session" do
|
||||
it 'sets the default locale' do
|
||||
expect(session[:locale]).to be_blank
|
||||
expect(I18n).to receive(:locale=).with(I18n.default_locale)
|
||||
expect(I18n).to receive(:locale=).with(I18n.default_locale).at_least(:once)
|
||||
get :welcome
|
||||
end
|
||||
end
|
||||
|
@ -85,9 +85,12 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
it 'sets the specified locale' do
|
||||
expect(controller).to receive(:set_locale).and_call_original
|
||||
expect(controller).to receive(:switch_locale).and_call_original
|
||||
i18n = instance_double 'i18n', locale: locale.to_s
|
||||
allow(I18n).to receive(:locale=).with(I18n.default_locale).and_call_original
|
||||
allow(I18n).to receive(:locale=).with(locale.to_s).and_return(i18n)
|
||||
perform_request
|
||||
expect(I18n.locale).to eq(locale)
|
||||
expect(i18n.locale.to_sym).to eq(locale)
|
||||
end
|
||||
|
||||
it 'assigns the exercise' do
|
||||
@ -107,7 +110,8 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
context 'when LTI outcomes are supported' do
|
||||
let(:message) { I18n.t('sessions.create_through_lti.session_with_outcome', consumer: consumer) }
|
||||
# The expected message should be localized in the requested localization
|
||||
let(:message) { I18n.t('sessions.create_through_lti.session_with_outcome', consumer: consumer, locale: locale) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:lti_outcome_service?).and_return(true)
|
||||
@ -118,7 +122,8 @@ describe SessionsController do
|
||||
end
|
||||
|
||||
context 'when LTI outcomes are not supported' do
|
||||
let(:message) { I18n.t('sessions.create_through_lti.session_without_outcome', consumer: consumer) }
|
||||
# The expected message should be localized in the requested localization
|
||||
let(:message) { I18n.t('sessions.create_through_lti.session_without_outcome', consumer: consumer, locale: locale) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:lti_outcome_service?).and_return(false)
|
||||
|
Reference in New Issue
Block a user