diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 8decc82ca..85209ca1e 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -39,7 +39,7 @@ class Users::DossiersController < UsersController unless params[:procedure_path].nil? procedure_path = ProcedurePath.where(path: params[:procedure_path]).last - if procedure_path.nil? + if procedure_path.nil? || procedure_path.procedure.nil? flash.alert = "Procédure inconnue" return redirect_to root_path else diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index abf8361a6..881184469 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -152,7 +152,7 @@ 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: procedure.path } } it { expect(subject.status).to eq 302 } it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) } @@ -166,6 +166,12 @@ describe Users::DossiersController, type: :controller do it { expect(subject.status).to eq 200 } end + + context 'when procedure is hidden' do + let(:procedure) { create(:procedure, :published, hidden_at: DateTime.now) } + + it { expect(subject).to redirect_to(root_path) } + end end describe 'POST #siret_informations' do