Fix bug when instruction repasse en construction twice
This commit is contained in:
parent
6de1e2ec58
commit
5f39d3eac8
2 changed files with 20 additions and 10 deletions
|
@ -92,8 +92,12 @@ module Gestionnaires
|
||||||
end
|
end
|
||||||
|
|
||||||
def repasser_en_construction
|
def repasser_en_construction
|
||||||
dossier.repasser_en_construction!(current_gestionnaire)
|
if dossier.en_construction?
|
||||||
flash.notice = 'Dossier repassé en construction.'
|
flash.notice = 'Le dossier est déjà en construction.'
|
||||||
|
else
|
||||||
|
dossier.repasser_en_construction!(current_gestionnaire)
|
||||||
|
flash.notice = 'Dossier repassé en construction.'
|
||||||
|
end
|
||||||
|
|
||||||
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
||||||
end
|
end
|
||||||
|
|
|
@ -128,21 +128,27 @@ describe Gestionnaires::DossiersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#repasser_en_construction' do
|
describe '#repasser_en_construction' do
|
||||||
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
dossier.en_instruction!
|
|
||||||
sign_in gestionnaire
|
sign_in gestionnaire
|
||||||
|
post :repasser_en_construction,
|
||||||
|
params: { procedure_id: procedure.id, dossier_id: dossier.id },
|
||||||
|
format: 'js'
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { post :repasser_en_construction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) }
|
||||||
|
it { expect(response).to have_http_status(:ok) }
|
||||||
|
it { expect(response.body).to include('.state-button') }
|
||||||
|
|
||||||
it 'change state to en_construction' do
|
context 'when the dossier has already been put en_construction' do
|
||||||
subject
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||||
|
|
||||||
dossier.reload
|
it 'warns about the error, but doesn’t raise' do
|
||||||
expect(dossier.state).to eq(Dossier.states.fetch(:en_construction))
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction))
|
||||||
|
expect(response).to have_http_status(:ok)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(subject.body).to include('.state-button') }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#terminer' do
|
describe '#terminer' do
|
||||||
|
|
Loading…
Reference in a new issue