diff --git a/app/controllers/admin/accompagnateurs_controller.rb b/app/controllers/admin/accompagnateurs_controller.rb index 584c80f68..83f9a6c94 100644 --- a/app/controllers/admin/accompagnateurs_controller.rb +++ b/app/controllers/admin/accompagnateurs_controller.rb @@ -19,6 +19,7 @@ class Admin::AccompagnateursController < AdminController partial: "admin/accompagnateurs/list_not_assign", array: true + @gestionnaire ||= Gestionnaire.new end def update diff --git a/app/controllers/admin/gestionnaires_controller.rb b/app/controllers/admin/gestionnaires_controller.rb index 651d22f38..e3ddc27a6 100644 --- a/app/controllers/admin/gestionnaires_controller.rb +++ b/app/controllers/admin/gestionnaires_controller.rb @@ -13,6 +13,7 @@ class Admin::GestionnairesController < AdminController def create @gestionnaire = Gestionnaire.find_by_email(params[:gestionnaire][:email]) + procedure_id = params[:procedure_id] if @gestionnaire.nil? new_gestionnaire! @@ -20,6 +21,7 @@ class Admin::GestionnairesController < AdminController assign_gestionnaire! end + return redirect_to admin_procedure_accompagnateurs_path(procedure_id: procedure_id) unless procedure_id.nil? redirect_to admin_gestionnaires_path end diff --git a/app/views/admin/accompagnateurs/show.html.haml b/app/views/admin/accompagnateurs/show.html.haml index 1c82ecc96..d4bee085c 100644 --- a/app/views/admin/accompagnateurs/show.html.haml +++ b/app/views/admin/accompagnateurs/show.html.haml @@ -11,6 +11,19 @@ %h3.text-info Disponibles = smart_listing_render :accompagnateurs_not_assign + %br + %h3 Ajouter un accompagnateur + #procedure_new.section.section-label + = form_for @gestionnaire, url: {controller: 'admin/gestionnaires', action: :create} do |f| + .row + .col-md-5.col-lg-5 + = hidden_field_tag :procedure_id, params[:procedure_id] + =render partial: 'admin/gestionnaires/informations', locals: {f: f} + .col-md-2.col-lg-2 + %br + %br + =f.submit 'Valider', class: 'btn btn-info', style: 'float:left' + .col-md-6.col-lg-6 %h3.text-success Affectés diff --git a/spec/controllers/admin/gestionnaires_controller_spec.rb b/spec/controllers/admin/gestionnaires_controller_spec.rb index 6b414d5e9..61ce9e98d 100644 --- a/spec/controllers/admin/gestionnaires_controller_spec.rb +++ b/spec/controllers/admin/gestionnaires_controller_spec.rb @@ -16,7 +16,8 @@ describe Admin::GestionnairesController, type: :controller do describe 'POST #create' do let(:email) { 'test@plop.com' } - subject { post :create, gestionnaire: {email: email} } + let(:procedure_id) { nil } + subject { post :create, gestionnaire: {email: email}, procedure_id: procedure_id } context 'When email is valid' do before do @@ -28,6 +29,14 @@ describe Admin::GestionnairesController, type: :controller do it { expect(response.status).to eq(302) } it { expect(response).to redirect_to admin_gestionnaires_path } + context 'when procedure_id params is not null' do + let(:procedure) { create :procedure } + let(:procedure_id) { procedure.id } + + it { expect(response.status).to eq(302) } + it { expect(response).to redirect_to admin_procedure_accompagnateurs_path(procedure_id: procedure_id) } + end + describe 'Gestionnaire attributs in database' do it { expect(gestionnaire.email).to eq(email) } end diff --git a/spec/views/admin/accompagnateurs/show.html.haml_spec.rb b/spec/views/admin/accompagnateurs/show.html.haml_spec.rb index bf5deb5a6..624bdc8a9 100644 --- a/spec/views/admin/accompagnateurs/show.html.haml_spec.rb +++ b/spec/views/admin/accompagnateurs/show.html.haml_spec.rb @@ -9,6 +9,7 @@ describe 'admin/accompagnateurs/show.html.haml', type: :view do before do assign(:procedure, procedure) + assign(:gestionnaire, Gestionnaire.new) assign(:accompagnateurs_assign, (smart_listing_create :accompagnateurs_assign, assign_gestionnaires,