Merge pull request #4056 from betagouv/fix-instructing-a-dossier-twice
Corrige un crash quand un Instructeur instruit un dossier déjà en instruction
This commit is contained in:
commit
1df948c2b9
2 changed files with 20 additions and 6 deletions
|
@ -80,8 +80,12 @@ module Gestionnaires
|
|||
end
|
||||
|
||||
def passer_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