Refactor locale with around method

This commit is contained in:
Sebastian Serth
2021-06-25 15:42:21 +02:00
parent e7cf4ef5db
commit 1b71163a77
3 changed files with 19 additions and 10 deletions

View File

@ -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)