dossiers_controller: warn properly when instructing a dossier twice
Fix #4055
This commit is contained in:
parent
89d5148b15
commit
422f4b9cdb
2 changed files with 20 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue