From c4970332eb1dbbac4ff515838d0e3e014f70f007 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sat, 23 Jan 2016 02:32:41 +0100 Subject: [PATCH] set locale=en to fix locale leakage from other requests --- .../application_controller.rb | 7 +++++++ .../application_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 spec/controllers/diaspora_federation/application_controller_spec.rb diff --git a/app/controllers/diaspora_federation/application_controller.rb b/app/controllers/diaspora_federation/application_controller.rb index f73b00e..586b503 100644 --- a/app/controllers/diaspora_federation/application_controller.rb +++ b/app/controllers/diaspora_federation/application_controller.rb @@ -1,5 +1,12 @@ module DiasporaFederation # Base-Controller for all DiasporaFederation-Controller class ApplicationController < ActionController::Base + before_action :set_locale + + # Fix locale leakage from other requests. + # Set "en" as locale for every federation request. + def set_locale + I18n.locale = :en + end end end diff --git a/spec/controllers/diaspora_federation/application_controller_spec.rb b/spec/controllers/diaspora_federation/application_controller_spec.rb new file mode 100644 index 0000000..79084c4 --- /dev/null +++ b/spec/controllers/diaspora_federation/application_controller_spec.rb @@ -0,0 +1,16 @@ +module DiasporaFederation + describe ApplicationController, type: :controller do + controller do + def index + head :ok + end + end + + describe "#set_locale" do + it "sets the default locale" do + expect(I18n).to receive(:locale=).with(:en) + get :index + end + end + end +end