filter out locale from stored query params

As 'locale' isn't a param we want to prefill a dossier, we ignore it
and remove it from the stored query params.
This commit is contained in:
sebastiencarceles 2023-02-08 15:23:50 +01:00
parent 7a254d124f
commit 6c5b82ebbf
2 changed files with 16 additions and 2 deletions

View file

@ -8,9 +8,9 @@ module QueryParamsStoreConcern
def store_query_params
# Don't override already stored params, because we could do goings and comings with authentication, and
# lost previously stored params
return if stored_query_params? || request.query_parameters.empty?
return if stored_query_params? || filtered_query_params.empty?
session[:stored_params] = request.query_parameters.to_json
session[:stored_params] = filtered_query_params.to_json
end
def retrieve_and_delete_stored_query_params
@ -22,4 +22,10 @@ module QueryParamsStoreConcern
def stored_query_params?
session[:stored_params].present?
end
private
def filtered_query_params
request.query_parameters.except(:locale, "locale")
end
end

View file

@ -36,6 +36,14 @@ RSpec.describe QueryParamsStoreConcern, type: :controller do
expect { store_query_params }.to change { session[:stored_params] }.from(nil).to(params.to_json)
end
end
context 'when params contain a locale' do
let(:params) { { locale: "fr", param2: "param2" } }
it "does not store the locale" do
expect { store_query_params }.to change { session[:stored_params] }.from(nil).to({ param2: "param2" }.to_json)
end
end
end
describe '#retrieve_and_delete_stored_query_params' do