From 06e7355d5b9886cdd00a597f4c7bef1448a75191 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 27 Mar 2019 16:46:35 +0000 Subject: [PATCH] commencer: fix invalid URL on test procedures Fix #3693 --- app/controllers/users/commencer_controller.rb | 2 +- .../users/commencer_controller_spec.rb | 48 ++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/controllers/users/commencer_controller.rb b/app/controllers/users/commencer_controller.rb index f74a56d7d..f42c5c31c 100644 --- a/app/controllers/users/commencer_controller.rb +++ b/app/controllers/users/commencer_controller.rb @@ -42,7 +42,7 @@ module Users def store_user_location! procedure = Procedure.find_by(path: params[:path]) - store_location_for(:user, commencer_path(path: procedure.path)) + store_location_for(:user, helpers.procedure_lien(procedure)) end end end diff --git a/spec/controllers/users/commencer_controller_spec.rb b/spec/controllers/users/commencer_controller_spec.rb index 2ef2a9ab5..cb6e8b069 100644 --- a/spec/controllers/users/commencer_controller_spec.rb +++ b/spec/controllers/users/commencer_controller_spec.rb @@ -18,7 +18,7 @@ describe Users::CommencerController, type: :controller do end end - context 'when the path is for a non-published procedure' do + context 'when the path is for a draft procedure' do let(:path) { draft_procedure.path } it 'redirects with an error message' do @@ -66,24 +66,50 @@ describe Users::CommencerController, type: :controller do end describe '#sign_in' do - subject { get :sign_in, params: { path: published_procedure.path } } + context 'for a published procedure' do + subject { get :sign_in, params: { path: published_procedure.path } } - it 'set the path to return after sign-in to the dossier creation path' do - subject - expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path)) + it 'set the path to return after sign-in to the procedure start page' do + subject + expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path)) + end + + it { expect(subject).to redirect_to(new_user_session_path) } end - it { expect(subject).to redirect_to(new_user_session_path) } + context 'for a draft procedure' do + subject { get :sign_in, params: { path: draft_procedure.path } } + + it 'set the path to return after sign-in to the draft procedure start page' do + subject + expect(controller.stored_location_for(:user)).to eq(commencer_test_path(path: draft_procedure.path)) + end + + it { expect(subject).to redirect_to(new_user_session_path) } + end end describe '#sign_up' do - subject { get :sign_up, params: { path: published_procedure.path } } + context 'for a published procedure' do + subject { get :sign_up, params: { path: published_procedure.path } } - it 'set the path to return after sign-up to the dossier creation path' do - subject - expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path)) + it 'set the path to return after sign-up to the procedure start page' do + subject + expect(controller.stored_location_for(:user)).to eq(commencer_path(path: published_procedure.path)) + end + + it { expect(subject).to redirect_to(new_user_registration_path) } end - it { expect(subject).to redirect_to(new_user_registration_path) } + context 'for a draft procedure' do + subject { get :sign_up, params: { path: draft_procedure.path } } + + it 'set the path to return after sign-up to the draft procedure start page' do + subject + expect(controller.stored_location_for(:user)).to eq(commencer_test_path(path: draft_procedure.path)) + end + + it { expect(subject).to redirect_to(new_user_registration_path) } + end end end