Dossier: #accepter_automatiquement!
This commit is contained in:
parent
0f3dedb0b6
commit
6ab2d124f9
2 changed files with 64 additions and 0 deletions
|
@ -301,6 +301,19 @@ class Dossier < ApplicationRecord
|
||||||
log_dossier_operation(gestionnaire, :accepter)
|
log_dossier_operation(gestionnaire, :accepter)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def accepter_automatiquement!
|
||||||
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
|
||||||
|
accepte!
|
||||||
|
|
||||||
|
if attestation.nil?
|
||||||
|
update(attestation: build_attestation)
|
||||||
|
end
|
||||||
|
|
||||||
|
NotificationMailer.send_closed_notification(self).deliver_later
|
||||||
|
log_dossier_operation(nil, :accepter, automatic_operation: true)
|
||||||
|
end
|
||||||
|
|
||||||
def refuser!(gestionnaire, motivation)
|
def refuser!(gestionnaire, motivation)
|
||||||
self.motivation = motivation
|
self.motivation = motivation
|
||||||
self.en_instruction_at ||= Time.zone.now
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
|
|
@ -761,6 +761,57 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#accepter!' do
|
||||||
|
let(:dossier) { create(:dossier) }
|
||||||
|
let!(:gestionnaire) { create(:gestionnaire) }
|
||||||
|
let!(:now) { Time.zone.parse('01/01/2100') }
|
||||||
|
let(:attestation) { Attestation.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(NotificationMailer).to receive(:send_closed_notification).and_return(double(deliver_later: true))
|
||||||
|
allow(dossier).to receive(:build_attestation).and_return(attestation)
|
||||||
|
|
||||||
|
Timecop.freeze(now)
|
||||||
|
dossier.accepter!(gestionnaire, 'motivation')
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
after { Timecop.return }
|
||||||
|
|
||||||
|
it { expect(dossier.motivation).to eq('motivation') }
|
||||||
|
it { expect(dossier.en_instruction_at).to eq(now) }
|
||||||
|
it { expect(dossier.processed_at).to eq(now) }
|
||||||
|
it { expect(dossier.state).to eq('accepte') }
|
||||||
|
it { expect(dossier.dossier_operation_logs.pluck(:gestionnaire_id, :operation, :automatic_operation)).to match([[gestionnaire.id, 'accepter', false]]) }
|
||||||
|
it { expect(NotificationMailer).to have_received(:send_closed_notification).with(dossier) }
|
||||||
|
it { expect(dossier.attestation).to eq(attestation) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#accepter_automatiquement!' do
|
||||||
|
let(:dossier) { create(:dossier) }
|
||||||
|
let!(:now) { Time.zone.parse('01/01/2100') }
|
||||||
|
let(:attestation) { Attestation.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(NotificationMailer).to receive(:send_closed_notification).and_return(double(deliver_later: true))
|
||||||
|
allow(dossier).to receive(:build_attestation).and_return(attestation)
|
||||||
|
|
||||||
|
Timecop.freeze(now)
|
||||||
|
dossier.accepter_automatiquement!
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
after { Timecop.return }
|
||||||
|
|
||||||
|
it { expect(dossier.motivation).to eq(nil) }
|
||||||
|
it { expect(dossier.en_instruction_at).to eq(now) }
|
||||||
|
it { expect(dossier.processed_at).to eq(now) }
|
||||||
|
it { expect(dossier.state).to eq('accepte') }
|
||||||
|
it { expect(dossier.dossier_operation_logs.pluck(:gestionnaire_id, :operation, :automatic_operation)).to match([[nil, 'accepter', true]]) }
|
||||||
|
it { expect(NotificationMailer).to have_received(:send_closed_notification).with(dossier) }
|
||||||
|
it { expect(dossier.attestation).to eq(attestation) }
|
||||||
|
end
|
||||||
|
|
||||||
describe '#passer_en_instruction!' do
|
describe '#passer_en_instruction!' do
|
||||||
let(:dossier) { create(:dossier) }
|
let(:dossier) { create(:dossier) }
|
||||||
let(:gestionnaire) { create(:gestionnaire) }
|
let(:gestionnaire) { create(:gestionnaire) }
|
||||||
|
|
Loading…
Reference in a new issue