Dossier: #passer_automatiquement_en_instruction!
This commit is contained in:
parent
cb4f843171
commit
0f3dedb0b6
2 changed files with 30 additions and 2 deletions
|
@ -274,6 +274,12 @@ class Dossier < ApplicationRecord
|
|||
log_dossier_operation(gestionnaire, :passer_en_instruction)
|
||||
end
|
||||
|
||||
def passer_automatiquement_en_instruction!
|
||||
en_instruction!
|
||||
|
||||
log_dossier_operation(nil, :passer_en_instruction, automatic_operation: true)
|
||||
end
|
||||
|
||||
def repasser_en_construction!(gestionnaire)
|
||||
self.en_instruction_at = nil
|
||||
en_construction!
|
||||
|
@ -317,10 +323,11 @@ class Dossier < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def log_dossier_operation(gestionnaire, operation)
|
||||
def log_dossier_operation(gestionnaire, operation, automatic_operation: false)
|
||||
dossier_operation_logs.create(
|
||||
gestionnaire: gestionnaire,
|
||||
operation: DossierOperationLog.operations.fetch(operation)
|
||||
operation: DossierOperationLog.operations.fetch(operation),
|
||||
automatic_operation: automatic_operation
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -760,4 +760,25 @@ describe Dossier do
|
|||
it { expect(long_expired_dossier).to be_retention_expired }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#passer_en_instruction!' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
|
||||
before { dossier.passer_en_instruction!(gestionnaire) }
|
||||
|
||||
it { expect(dossier.state).to eq('en_instruction') }
|
||||
it { expect(dossier.followers_gestionnaires).to include(gestionnaire) }
|
||||
it { expect(dossier.dossier_operation_logs.pluck(:gestionnaire_id, :operation)).to match([[gestionnaire.id, 'passer_en_instruction']]) }
|
||||
end
|
||||
|
||||
describe '#passer_automatiquement_en_instruction!' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
|
||||
before { dossier.passer_automatiquement_en_instruction! }
|
||||
|
||||
it { expect(dossier.followers_gestionnaires).not_to include(gestionnaire) }
|
||||
it { expect(dossier.dossier_operation_logs.pluck(:gestionnaire_id, :operation, :automatic_operation)).to match([[nil, 'passer_en_instruction', true]]) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue