diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index af0f42b6f..685db3f81 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -80,8 +80,12 @@ module Gestionnaires end def passer_en_instruction - dossier.passer_en_instruction!(current_gestionnaire) - flash.notice = 'Dossier passé en instruction.' + if dossier.en_instruction? + flash.notice = 'Le dossier est déjà en instruction.' + else + dossier.passer_en_instruction!(current_gestionnaire) + flash.notice = 'Dossier passé en instruction.' + end render partial: 'state_button_refresh', locals: { dossier: dossier } end diff --git a/spec/controllers/gestionnaires/dossiers_controller_spec.rb b/spec/controllers/gestionnaires/dossiers_controller_spec.rb index 570f6b3c4..ca53d1210 100644 --- a/spec/controllers/gestionnaires/dossiers_controller_spec.rb +++ b/spec/controllers/gestionnaires/dossiers_controller_spec.rb @@ -105,16 +105,26 @@ describe Gestionnaires::DossiersController, type: :controller do end describe '#passer_en_instruction' do + let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } + before do - dossier.en_construction! sign_in gestionnaire post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' - dossier.reload end - it { expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction)) } - it { expect(response.body).to include('.state-button') } + it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) } it { expect(gestionnaire.follow?(dossier)).to be true } + it { expect(response).to have_http_status(:ok) } + it { expect(response.body).to include('.state-button') } + + context 'when the dossier has already been put en_instruction' do + let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } + + it 'warns about the error, but doesn’t raise' do + expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) + expect(response).to have_http_status(:ok) + end + end end describe '#repasser_en_construction' do