dossiers_controller: warn properly when instructing a dossier twice

Fix #4055
This commit is contained in:
Pierre de La Morinerie 2019-07-08 17:58:45 +02:00
parent 89d5148b15
commit 422f4b9cdb
2 changed files with 20 additions and 6 deletions

View file

@ -80,8 +80,12 @@ module Gestionnaires
end end
def passer_en_instruction def passer_en_instruction
dossier.passer_en_instruction!(current_gestionnaire) if dossier.en_instruction?
flash.notice = 'Dossier passé 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 } render partial: 'state_button_refresh', locals: { dossier: dossier }
end end

View file

@ -105,16 +105,26 @@ describe Gestionnaires::DossiersController, type: :controller do
end end
describe '#passer_en_instruction' do describe '#passer_en_instruction' do
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
before do before do
dossier.en_construction!
sign_in gestionnaire sign_in gestionnaire
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js'
dossier.reload
end end
it { expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction)) } it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
it { expect(response.body).to include('.state-button') }
it { expect(gestionnaire.follow?(dossier)).to be true } 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 doesnt raise' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to have_http_status(:ok)
end
end
end end
describe '#repasser_en_construction' do describe '#repasser_en_construction' do