Fix crash with inexistent paths

This commit is contained in:
Paul Chavard 2018-05-23 15:36:50 +02:00
parent b421f48b21
commit ceddf65f6c
2 changed files with 10 additions and 3 deletions

View file

@ -43,7 +43,7 @@ class Users::DossiersController < UsersController
def commencer_test def commencer_test
procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
procedure = procedure_path.test_procedure procedure = procedure_path&.test_procedure
if procedure.present? if procedure.present?
redirect_to new_users_dossier_path(procedure_id: procedure.id) redirect_to new_users_dossier_path(procedure_id: procedure.id)
@ -55,7 +55,7 @@ class Users::DossiersController < UsersController
def commencer def commencer
procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
procedure = procedure_path.procedure procedure = procedure_path&.procedure
if procedure.present? if procedure.present?
if procedure.archivee? if procedure.archivee?

View file

@ -152,7 +152,8 @@ describe Users::DossiersController, type: :controller do
end end
describe 'GET #commencer' do 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.status).to eq 302 }
it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) } 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) } it { expect(subject).to redirect_to(root_path) }
end end
context 'when procedure path dose not exist' do
let(:path) { 'hello' }
it { expect(subject).to redirect_to(root_path) }
end
end end
describe 'POST #siret_informations' do describe 'POST #siret_informations' do