diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index e2c19de65..c206b3724 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -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 diff --git a/app/views/administrateurs/procedures/_informations.html.haml b/app/views/administrateurs/procedures/_informations.html.haml index 972a36d51..3e1e19e2f 100644 --- a/app/views/administrateurs/procedures/_informations.html.haml +++ b/app/views/administrateurs/procedures/_informations.html.haml @@ -25,7 +25,7 @@ = t(:notice, scope: [:administrateurs, :duree_conservation_dossiers_dans_ds]) - if f.object.duree_conservation_dossiers_dans_ds.to_i < Procedure::NEW_MAX_DUREE_CONSERVATION = t(:new_duration_constraint, scope: [:administrateurs, :duree_conservation_dossiers_dans_ds], new_duration_in_month: Procedure::NEW_MAX_DUREE_CONSERVATION) -= f.number_field :duree_conservation_dossiers_dans_ds, { class: 'form-control', placeholder: '6', required: true }.merge(f.object.duree_conservation_etendue_par_ds ? {} : { max: 12 }) += f.number_field :duree_conservation_dossiers_dans_ds, { class: 'form-control', placeholder: '6', required: true }.merge(f.object.duree_conservation_etendue_par_ds ? {} : { max: Procedure::NEW_MAX_DUREE_CONSERVATION }) - if @procedure.created_at.present? = f.label :lien_site_web do diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index 034ec1704..d6667b9e4 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -342,6 +342,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 }