diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 4c30d3344..48d1c27ce 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -43,7 +43,7 @@ class Users::DossiersController < UsersController def commencer_test procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) - procedure = procedure_path.test_procedure + procedure = procedure_path&.test_procedure if procedure.present? redirect_to new_users_dossier_path(procedure_id: procedure.id) @@ -55,7 +55,7 @@ class Users::DossiersController < UsersController def commencer procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) - procedure = procedure_path.procedure + procedure = procedure_path&.procedure if procedure.present? if procedure.archivee? diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 8eff31ad1..216d82fa0 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -152,7 +152,8 @@ describe Users::DossiersController, type: :controller do end describe 'GET #commencer' do - subject { get :commencer, params: { procedure_path: procedure.path } } + subject { get :commencer, params: { procedure_path: path } } + let(:path) { procedure.path } it { expect(subject.status).to eq 302 } it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) } @@ -172,6 +173,12 @@ describe Users::DossiersController, type: :controller do it { expect(subject).to redirect_to(root_path) } end + + context 'when procedure path dose not exist' do + let(:path) { 'hello' } + + it { expect(subject).to redirect_to(root_path) } + end end describe 'POST #siret_informations' do