[fix #3683] Dossier: add repasser_en_instruction!
This commit is contained in:
parent
b79220e711
commit
b2c987ff0d
4 changed files with 34 additions and 0 deletions
|
@ -95,6 +95,7 @@ module Gestionnaires
|
|||
|
||||
def repasser_en_instruction
|
||||
flash.notice = "Le dossier #{dossier.id} a été repassé en instruction."
|
||||
dossier.repasser_en_instruction!(current_gestionnaire)
|
||||
|
||||
render partial: 'state_button_refresh', locals: { dossier: dossier }
|
||||
end
|
||||
|
|
|
@ -302,6 +302,14 @@ class Dossier < ApplicationRecord
|
|||
log_dossier_operation(gestionnaire, :repasser_en_construction)
|
||||
end
|
||||
|
||||
def repasser_en_instruction!(gestionnaire)
|
||||
update(state: Dossier.states.fetch(:en_instruction), processed_at: nil, motivation: nil)
|
||||
attestation&.destroy
|
||||
DossierMailer.notify_revert_to_instruction(self).deliver_later
|
||||
|
||||
log_dossier_operation(gestionnaire, :repasser_en_instruction)
|
||||
end
|
||||
|
||||
def accepter!(gestionnaire, motivation, justificatif = nil)
|
||||
self.motivation = motivation
|
||||
self.en_instruction_at ||= Time.zone.now
|
||||
|
|
|
@ -2,6 +2,7 @@ class DossierOperationLog < ApplicationRecord
|
|||
enum operation: {
|
||||
passer_en_instruction: 'passer_en_instruction',
|
||||
repasser_en_construction: 'repasser_en_construction',
|
||||
repasser_en_instruction: 'repasser_en_instruction',
|
||||
accepter: 'accepter',
|
||||
refuser: 'refuser',
|
||||
classer_sans_suite: 'classer_sans_suite',
|
||||
|
|
|
@ -987,4 +987,28 @@ describe Dossier do
|
|||
it { expect(last_operation.operation).to eq('supprimer') }
|
||||
it { expect(last_operation.automatic_operation?).to be_falsey }
|
||||
end
|
||||
|
||||
describe '#repasser_en_instruction!' do
|
||||
let(:dossier) { create(:dossier, :refuse, :with_attestation) }
|
||||
let!(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:last_operation) { dossier.dossier_operation_logs.last }
|
||||
|
||||
before do
|
||||
Timecop.freeze
|
||||
allow(DossierMailer).to receive(:notify_revert_to_instruction)
|
||||
.and_return(double(deliver_later: true))
|
||||
dossier.repasser_en_instruction!(gestionnaire)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.state).to eq('en_instruction') }
|
||||
it { expect(dossier.processed_at).to be_nil }
|
||||
it { expect(dossier.motivation).to be_nil }
|
||||
it { expect(dossier.attestation).to be_nil }
|
||||
it { expect(last_operation.operation).to eq('repasser_en_instruction') }
|
||||
it { expect(JSON.parse(last_operation.serialized.download)['author']['email']).to eq(gestionnaire.email) }
|
||||
it { expect(DossierMailer).to have_received(:notify_revert_to_instruction).with(dossier) }
|
||||
|
||||
after { Timecop.return }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue