From 9793128f618618d2c9a39902f0dc6eb3fc5bea4c Mon Sep 17 00:00:00 2001 From: Judith Date: Tue, 7 Jul 2020 12:31:52 +0200 Subject: [PATCH] 'Services' routes moved under 'new_administrateur' scope and '/admn' added in their url --- app/controllers/new_administrateur/services_controller.rb | 8 ++++---- app/views/admin/procedures/show.html.haml | 4 ++-- ...left_panel_admin_procedurescontroller_navbar.html.haml | 2 +- app/views/new_administrateur/services/_form.html.haml | 2 +- app/views/new_administrateur/services/edit.html.haml | 2 +- app/views/new_administrateur/services/index.html.haml | 6 +++--- app/views/new_administrateur/services/new.html.haml | 2 +- config/routes.rb | 2 -- .../new_administrateur/services_controller_spec.rb | 8 ++++---- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 236c05238..a7c9edf46 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -15,7 +15,7 @@ module NewAdministrateur @service.administrateur = current_administrateur if @service.save - redirect_to services_path(procedure_id: params[:procedure_id]), + redirect_to admin_services_path(procedure_id: params[:procedure_id]), notice: "#{@service.nom} créé" else @procedure = procedure @@ -33,7 +33,7 @@ module NewAdministrateur @service = service if @service.update(service_params) - redirect_to services_path(procedure_id: params[:procedure_id]), + redirect_to admin_services_path(procedure_id: params[:procedure_id]), notice: "#{@service.nom} modifié" else @procedure = procedure @@ -62,10 +62,10 @@ module NewAdministrateur message = "les démarches #{service_to_destroy.procedures.map(&:libelle).join(', ')} utilisent encore le service #{service.nom}. Veuillez les affecter à un autre service avant de pouvoir le supprimer" end flash[:alert] = message - redirect_to services_path(procedure_id: params[:procedure_id]) + redirect_to admin_services_path(procedure_id: params[:procedure_id]) else service_to_destroy.destroy - redirect_to services_path(procedure_id: params[:procedure_id]), + redirect_to admin_services_path(procedure_id: params[:procedure_id]), notice: "#{service_to_destroy.nom} est supprimé" end end diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index a3d22ac03..e40890213 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -111,13 +111,13 @@ - if @procedure.missing_instructeurs? && @procedure.service.nil? et - if @procedure.service.nil? - = link_to("un service", services_path(procedure_id: @procedure)) + = link_to("un service", admin_services_path(procedure_id: @procedure)) \. - else - if @procedure.missing_steps.include?(:service) %p.alert.alert-danger Vous devez renseigner les coordonnées de votre Service administratif avant de pouvoir publier votre démarche. - = link_to 'Cliquez ici.', (@current_administrateur.services.present? ? url_for(services_path(procedure_id: @procedure.id)) : url_for(new_service_path(procedure_id: @procedure.id))) + = link_to 'Cliquez ici.', (@current_administrateur.services.present? ? url_for(admin_services_path(procedure_id: @procedure.id)) : url_for(new_admin_service_path(procedure_id: @procedure.id))) - if @procedure.missing_steps.include?(:instructeurs) %p.alert.alert-danger diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml index a262889dc..0d6d0eb8c 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_navbar.html.haml @@ -20,7 +20,7 @@ .procedure-list-element{ class: ('active' if active == 'Description') } Description - %a#onglet-services{ href: (@procedure.service.present? || current_administrateur.services.present?) ? url_for(services_path(procedure_id: @procedure.id)) : url_for(new_service_path(procedure_id: @procedure.id)) } + %a#onglet-services{ href: (@procedure.service.present? || current_administrateur.services.present?) ? url_for(admin_services_path(procedure_id: @procedure.id)) : url_for(new_admin_service_path(procedure_id: @procedure.id)) } .procedure-list-element Service - if @procedure.missing_steps.include?(:service) diff --git a/app/views/new_administrateur/services/_form.html.haml b/app/views/new_administrateur/services/_form.html.haml index efd355d8b..5be9f9f2b 100644 --- a/app/views/new_administrateur/services/_form.html.haml +++ b/app/views/new_administrateur/services/_form.html.haml @@ -1,4 +1,4 @@ -= form_for service, html: { class: 'form' } do |f| += form_with model: [ :admin, service] , html: { class: 'form' } do |f| = f.label :nom do Nom diff --git a/app/views/new_administrateur/services/edit.html.haml b/app/views/new_administrateur/services/edit.html.haml index 7542bdd10..95d54c652 100644 --- a/app/views/new_administrateur/services/edit.html.haml +++ b/app/views/new_administrateur/services/edit.html.haml @@ -1,7 +1,7 @@ = render partial: 'new_administrateur/breadcrumbs', locals: { steps: [link_to('Démarches', admin_procedures_path), link_to(@procedure.libelle, admin_procedure_path(@procedure)), - link_to('choix du service', services_path(procedure_id: @procedure.id)), + link_to('choix du service', admin_services_path(procedure_id: @procedure.id)), 'modifier le service'] } .container diff --git a/app/views/new_administrateur/services/index.html.haml b/app/views/new_administrateur/services/index.html.haml index 486fb7269..58ce9bc22 100644 --- a/app/views/new_administrateur/services/index.html.haml +++ b/app/views/new_administrateur/services/index.html.haml @@ -24,7 +24,7 @@ %th nom %th.change - = link_to('Nouveau service', new_service_path(procedure_id: @procedure.id), class: 'button') + = link_to('Nouveau service', new_admin_service_path(procedure_id: @procedure.id), class: 'button') %tbody - @services.each do |service| @@ -32,8 +32,8 @@ %td = service.nom %td.change - = link_to('modifier', edit_service_path(service, procedure_id: @procedure.id)) + = link_to('modifier', edit_admin_service_path(service, procedure_id: @procedure.id)) = link_to 'supprimer', - service_path(service, procedure_id: @procedure.id), + admin_service_path(service, procedure_id: @procedure.id), method: :delete, data: { confirm: "Confirmez vous la suppression de #{service.nom}" } diff --git a/app/views/new_administrateur/services/new.html.haml b/app/views/new_administrateur/services/new.html.haml index 4ae80edf5..a51ab24d1 100644 --- a/app/views/new_administrateur/services/new.html.haml +++ b/app/views/new_administrateur/services/new.html.haml @@ -1,7 +1,7 @@ = render partial: 'new_administrateur/breadcrumbs', locals: { steps: [link_to('Démarches', admin_procedures_path), link_to(@procedure.libelle, admin_procedure_path(@procedure)), - link_to('choix du service', services_path(procedure_id: @procedure.id)), + link_to('choix du service', admin_services_path(procedure_id: @procedure.id)), 'nouveau service'] } .container diff --git a/config/routes.rb b/config/routes.rb index cb4ce92f1..71827ae76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -406,9 +406,7 @@ Rails.application.routes.draw do get 'preview', on: :member end end - end - scope module: 'new_administrateur' do resources :services, except: [:show] do collection do patch 'add_to_procedure' diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index a0bb5e0ad..9634148f3 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -33,7 +33,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(Service.last.telephone).to eq('1234') } it { expect(Service.last.horaires).to eq('horaires') } it { expect(Service.last.adresse).to eq('adresse') } - it { expect(response).to redirect_to(services_path(procedure_id: 12)) } + it { expect(response).to redirect_to(admin_services_path(procedure_id: 12)) } end context 'when submitting an invalid service' do @@ -64,7 +64,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(flash.notice).to eq('nom modifié') } it { expect(Service.last.nom).to eq('nom') } it { expect(Service.last.type_organisme).to eq(Service.type_organismes.fetch(:association)) } - it { expect(response).to redirect_to(services_path(procedure_id: procedure.id)) } + it { expect(response).to redirect_to(admin_services_path(procedure_id: procedure.id)) } end context 'when updating a service with invalid data' do @@ -119,7 +119,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect { service.reload }.to raise_error(ActiveRecord::RecordNotFound) } it { expect(flash.alert).to be_nil } it { expect(flash.notice).to eq("#{service.nom} est supprimé") } - it { expect(response).to redirect_to(services_path(procedure_id: 12)) } + it { expect(response).to redirect_to(admin_services_path(procedure_id: 12)) } end context 'when a service still has some related procedures' do @@ -133,7 +133,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(service.reload).not_to be_nil } it { expect(flash.alert).to eq("la démarche #{procedure.libelle} utilise encore le service service. Veuillez l'affecter à un autre service avant de pouvoir le supprimer") } it { expect(flash.notice).to be_nil } - it { expect(response).to redirect_to(services_path(procedure_id: 12)) } + it { expect(response).to redirect_to(admin_services_path(procedure_id: 12)) } end end end