diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 0f954bde3..79fe2d235 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -71,6 +71,10 @@ class Admin::ProceduresController < AdminController render 'new' else flash.notice = 'Démarche enregistrée.' + gestionnaire = Gestionnaire.find_by(email: current_administrateur.email) + if gestionnaire + gestionnaire.assign_to_procedure(@procedure) + end redirect_to admin_procedure_types_de_champ_path(procedure_id: @procedure.id) end end diff --git a/app/views/admin/instructeurs/show.html.haml b/app/views/admin/instructeurs/show.html.haml index 83effd8c4..3f0c6a2d3 100644 --- a/app/views/admin/instructeurs/show.html.haml +++ b/app/views/admin/instructeurs/show.html.haml @@ -18,9 +18,6 @@ %br %br = f.submit 'Valider', class: 'btn btn-info', style: 'float: left;', id: 'add-gestionnaire-email' - %br - .alert.alert-info - Astuce : ajoutez votre adresse email pour tester la partie instructeur. .col-xs-6 %h3.text-success Affectés = smart_listing_render :instructeurs_assign diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 6db8cde08..4cdbad152 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -197,6 +197,19 @@ describe Admin::ProceduresController, type: :controller do it { expect(flash[:notice]).to be_present } end + + context 'when procedure is correctly saved' do + let!(:gestionnaire) { create(:gestionnaire, email: admin.email) } + + before do + post :create, params: { procedure: procedure_params } + end + + describe "admin can also instruct the procedure as a gestionnaire" do + subject { Procedure.last } + it { expect(subject.gestionnaires).to include(gestionnaire) } + end + end end context 'when many attributs are not valid' do