fix(procedure): deal nicely with custom NEW_MAX_DUREE_CONSERVATION

This commit is contained in:
François Vantomme 2023-01-12 13:04:21 +01:00
parent d60d626a91
commit e794d4f77b
No known key found for this signature in database
GPG key ID: 7C090509B9BF8D09
2 changed files with 24 additions and 1 deletions

View file

@ -115,7 +115,11 @@ module Administrateurs
end
def create
@procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur]))
new_procedure_params = { max_duree_conservation_dossiers_dans_ds: Procedure::NEW_MAX_DUREE_CONSERVATION }
.merge(procedure_params)
.merge(administrateurs: [current_administrateur])
@procedure = Procedure.new(new_procedure_params)
@procedure.draft_revision = @procedure.revisions.build
if !@procedure.save

View file

@ -333,6 +333,25 @@ describe Administrateurs::ProceduresController, type: :controller do
it { expect(flash[:notice]).to be_present }
end
describe "procedure is saved with custom retention period" do
let(:duree_conservation_dossiers_dans_ds) { 17 }
before do
stub_const("Procedure::NEW_MAX_DUREE_CONSERVATION", 18)
end
subject { post :create, params: { procedure: procedure_params } }
it { expect { subject }.to change { Procedure.count }.by(1) }
it "must save retention period and max retention period" do
subject
last_procedure = Procedure.last
expect(last_procedure.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds)
expect(last_procedure.max_duree_conservation_dossiers_dans_ds).to eq(Procedure::NEW_MAX_DUREE_CONSERVATION)
end
end
context 'when procedure is correctly saved' do
let(:instructeur) { admin.instructeur }