Same for go back in instruction

This commit is contained in:
simon lehericey 2019-07-11 11:52:24 +02:00
parent 5f39d3eac8
commit 768a298c2d
2 changed files with 30 additions and 2 deletions

View file

@ -103,8 +103,12 @@ module Gestionnaires
end
def repasser_en_instruction
flash.notice = "Le dossier #{dossier.id} a été repassé en instruction."
dossier.repasser_en_instruction!(current_gestionnaire)
if dossier.en_instruction?
flash.notice = 'Le dossier est déjà en instruction.'
else
flash.notice = "Le dossier #{dossier.id} a été repassé en instruction."
dossier.repasser_en_instruction!(current_gestionnaire)
end
render partial: 'state_button_refresh', locals: { dossier: dossier }
end

View file

@ -151,6 +151,30 @@ describe Gestionnaires::DossiersController, type: :controller do
end
end
describe '#repasser_en_instruction' do
let(:dossier) { create(:dossier, :refuse, procedure: procedure) }
before do
sign_in gestionnaire
post :repasser_en_instruction,
params: { procedure_id: procedure.id, dossier_id: dossier.id },
format: 'js'
end
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
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
describe '#terminer' do
context "with refuser" do
before do