From f25fa83b6d99d9697923a2faa03390768c1d27b8 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 28 Jul 2020 22:20:38 +0100 Subject: [PATCH] FIX: Ensure correct locale is set during RenderEmpty responses Follow-up to bcb0e623 --- app/controllers/application_controller.rb | 2 +- spec/requests/application_controller_spec.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ea1192241bc..87c3ba014e3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -110,7 +110,7 @@ class ApplicationController < ActionController::Base class PluginDisabled < StandardError; end rescue_from RenderEmpty do - render 'default/empty' + with_resolved_locale { render 'default/empty' } end rescue_from ArgumentError do |e| diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb index 4d832e7c533..2a49f4bfecd 100644 --- a/spec/requests/application_controller_spec.rb +++ b/spec/requests/application_controller_spec.rb @@ -687,8 +687,9 @@ RSpec.describe ApplicationController do end context "with a logged in user" do + let(:user) { Fabricate(:user, locale: :fr) } + before do - user = Fabricate(:user, locale: :fr) sign_in(user) end @@ -704,6 +705,12 @@ RSpec.describe ApplicationController do expected_title = I18n.t("page_not_found.title", locale: :fr) expect(response.body).to include(CGI.escapeHTML(expected_title)) end + + it "serves a RenderEmpty page in the preferred locale" do + get "/u/#{user.username}/preferences/interface" + expect(response.status).to eq(200) + expect(response.body).to have_tag('script', with: { src: "/assets/locales/fr.js" }) + end end end