[fix #3683] Dossier: add repasser_en_instruction!

This commit is contained in:
simon lehericey 2019-07-01 17:45:03 +02:00
parent b79220e711
commit b2c987ff0d
4 changed files with 34 additions and 0 deletions

View file

@ -95,6 +95,7 @@ module Gestionnaires
def repasser_en_instruction def repasser_en_instruction
flash.notice = "Le dossier #{dossier.id} a été repassé 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 } render partial: 'state_button_refresh', locals: { dossier: dossier }
end end

View file

@ -302,6 +302,14 @@ class Dossier < ApplicationRecord
log_dossier_operation(gestionnaire, :repasser_en_construction) log_dossier_operation(gestionnaire, :repasser_en_construction)
end 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) def accepter!(gestionnaire, motivation, justificatif = nil)
self.motivation = motivation self.motivation = motivation
self.en_instruction_at ||= Time.zone.now self.en_instruction_at ||= Time.zone.now

View file

@ -2,6 +2,7 @@ class DossierOperationLog < ApplicationRecord
enum operation: { enum operation: {
passer_en_instruction: 'passer_en_instruction', passer_en_instruction: 'passer_en_instruction',
repasser_en_construction: 'repasser_en_construction', repasser_en_construction: 'repasser_en_construction',
repasser_en_instruction: 'repasser_en_instruction',
accepter: 'accepter', accepter: 'accepter',
refuser: 'refuser', refuser: 'refuser',
classer_sans_suite: 'classer_sans_suite', classer_sans_suite: 'classer_sans_suite',

View file

@ -987,4 +987,28 @@ describe Dossier do
it { expect(last_operation.operation).to eq('supprimer') } it { expect(last_operation.operation).to eq('supprimer') }
it { expect(last_operation.automatic_operation?).to be_falsey } it { expect(last_operation.automatic_operation?).to be_falsey }
end 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 end