From d08707f62e29391f126252450e894523fb58f818 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 28 Jun 2021 16:08:24 +0200 Subject: [PATCH] Fix switch_locale to return the block result --- app/controllers/application_controller.rb | 2 +- app/controllers/concerns/submission_scoring.rb | 15 ++++++++------- spec/controllers/application_controller_spec.rb | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 327437a7..9db3ae0d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -75,8 +75,8 @@ class ApplicationController < ActionController::Base def switch_locale(&action) session[:locale] = params[:custom_locale] || params[:locale] || session[:locale] locale = session[:locale] || I18n.default_locale - I18n.with_locale(locale, &action) Sentry.set_extras(locale: locale) + I18n.with_locale(locale, &action) end private :switch_locale diff --git a/app/controllers/concerns/submission_scoring.rb b/app/controllers/concerns/submission_scoring.rb index d5e5f7fc..371a3fa9 100644 --- a/app/controllers/concerns/submission_scoring.rb +++ b/app/controllers/concerns/submission_scoring.rb @@ -57,13 +57,14 @@ module SubmissionScoring private :execute_test_file def feedback_message(file, output) - set_locale - if output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_test' - I18n.t('exercises.implement.default_test_feedback') - elsif output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_linter' - I18n.t('exercises.implement.default_linter_feedback') - else - render_markdown(file.feedback_message) + switch_locale do + if output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_test' + I18n.t('exercises.implement.default_test_feedback') + elsif output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_linter' + I18n.t('exercises.implement.default_linter_feedback') + else + render_markdown(file.feedback_message) + end end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index d9783d41..89d77833 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -35,7 +35,7 @@ describe ApplicationController do expect_redirect(:root) end - describe '#set_locale' do + describe '#switch_locale' do let(:locale) { :de } context 'when specifying a locale' do