Fix bug when an instructeur closes a dossier already closed
This commit is contained in:
parent
01ba459b73
commit
6de1e2ec58
2 changed files with 30 additions and 10 deletions
|
@ -3,6 +3,7 @@ module Gestionnaires
|
|||
include ActionView::Helpers::NumberHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
include CreateAvisConcern
|
||||
include DossierHelper
|
||||
|
||||
after_action :mark_demande_as_read, only: :show
|
||||
after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire]
|
||||
|
@ -108,16 +109,20 @@ module Gestionnaires
|
|||
motivation = params[:dossier] && params[:dossier][:motivation]
|
||||
justificatif = params[:dossier] && params[:dossier][:justificatif_motivation]
|
||||
|
||||
case params[:process_action]
|
||||
when "refuser"
|
||||
dossier.refuser!(current_gestionnaire, motivation, justificatif)
|
||||
flash.notice = "Dossier considéré comme refusé."
|
||||
when "classer_sans_suite"
|
||||
dossier.classer_sans_suite!(current_gestionnaire, motivation, justificatif)
|
||||
flash.notice = "Dossier considéré comme sans suite."
|
||||
when "accepter"
|
||||
dossier.accepter!(current_gestionnaire, motivation, justificatif)
|
||||
flash.notice = "Dossier traité avec succès."
|
||||
if dossier.termine?
|
||||
flash.notice = "Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"
|
||||
else
|
||||
case params[:process_action]
|
||||
when "refuser"
|
||||
dossier.refuser!(current_gestionnaire, motivation, justificatif)
|
||||
flash.notice = "Dossier considéré comme refusé."
|
||||
when "classer_sans_suite"
|
||||
dossier.classer_sans_suite!(current_gestionnaire, motivation, justificatif)
|
||||
flash.notice = "Dossier considéré comme sans suite."
|
||||
when "accepter"
|
||||
dossier.accepter!(current_gestionnaire, motivation, justificatif)
|
||||
flash.notice = "Dossier traité avec succès."
|
||||
end
|
||||
end
|
||||
|
||||
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
||||
|
|
|
@ -319,6 +319,21 @@ describe Gestionnaires::DossiersController, type: :controller do
|
|||
it { expect(subject.body).to include('.state-button') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a dossier is already closed' do
|
||||
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
||||
|
||||
before { allow(dossier).to receive(:accepter!) }
|
||||
|
||||
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
||||
|
||||
it 'does not close it again' do
|
||||
subject
|
||||
|
||||
expect(dossier).not_to have_received(:accepter!)
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create_commentaire" do
|
||||
|
|
Loading…
Reference in a new issue