diff --git a/app/controllers/good_job/application_controller.rb b/app/controllers/good_job/application_controller.rb index 02438a6f2..fc5a36ed1 100644 --- a/app/controllers/good_job/application_controller.rb +++ b/app/controllers/good_job/application_controller.rb @@ -35,7 +35,9 @@ def switch_locale(&action) end def current_locale - if params[:locale] + if request.GET['locale'] + request.GET['locale'] + elsif params[:locale] params[:locale] elsif good_job_available_locales.exclude?(I18n.default_locale) && I18n.available_locales.include?(:en) :en diff --git a/spec/app/controllers/good_job/application_controller_spec.rb b/spec/app/controllers/good_job/application_controller_spec.rb new file mode 100644 index 000000000..9fabcde41 --- /dev/null +++ b/spec/app/controllers/good_job/application_controller_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true +require "rails_helper" + +RSpec.describe GoodJob::ApplicationController, type: :controller do + render_views # seems required for Rails HEAD + + controller do + def index + render plain: "OK" + end + end + + describe "#current_locale" do + it "defers to GET queries of params (to allow setting `mount...defaults: { locale: X })`" do + allow(controller.params).to receive(:[]).with(:locale).and_return(:en) + allow(controller.request.GET).to receive(:[]).with('locale').and_return(:de) + + expect(controller.send(:current_locale)).to eq(:de) + end + end +end