controllers: use standard action names in ExpertsProceduresController

This commit is contained in:
Pierre de La Morinerie 2021-04-06 11:42:21 +00:00
parent 3f25624a5a
commit 7acb4cee83
4 changed files with 17 additions and 19 deletions

View file

@ -1,8 +1,8 @@
module NewAdministrateur
class ExpertsProceduresController < AdministrateurController
before_action :retrieve_procedure, only: [:add_expert_to_procedure, :revoke_expert_from_procedure]
before_action :retrieve_procedure
def add_expert_to_procedure
def create
emails = params['emails'].presence || [].to_json
emails = JSON.parse(emails).map(&:strip).map(&:downcase)
@ -32,7 +32,7 @@ module NewAdministrateur
redirect_to admin_procedure_invited_expert_list_path(@procedure)
end
def revoke_expert_from_procedure
def destroy
expert_procedure = ExpertsProcedure.find_by!(procedure: @procedure, id: params[:id])
expert_email = expert_procedure.expert.email
expert_procedure.update!(revoked_at: Time.zone.now)

View file

@ -11,7 +11,7 @@
.card
.card-title Affecter des experts à la démarche
= form_for :experts_procedure,
url: admin_procedure_add_expert_to_procedure_path(@procedure),
url: admin_procedure_experts_path(@procedure),
html: { class: 'form' } do |f|
.instructeur-wrapper
@ -57,13 +57,11 @@
%span.toggle-switch-label.on
%span.toggle-switch-label.off
%td.actions= button_to 'retirer',
{ action: "revoke_expert_from_procedure", :controller=>"new_administrateur/experts_procedures" },
{ method: :put,
data: { confirm: "Êtes-vous sûr de vouloir révoquer l'expert « #{expert_procedure.expert.email} » de la démarche #{expert_procedure.procedure.libelle} ? Les instructeurs ne pourront plus lui demander d'avis" },
params: { expert_procedure: { id: expert_procedure.id }},
class: 'button' }
admin_procedure_expert_path(id: expert_procedure, procedure: @procedure),
method: :delete,
data: { confirm: "Êtes-vous sûr de vouloir révoquer l'expert « #{expert_procedure.expert.email} » de la démarche #{expert_procedure.procedure.libelle} ? Les instructeurs ne pourront plus lui demander d'avis" },
class: 'button'
- else
.blank-tab
%h2.empty-text Aucun expert invité pour le moment.
%p.empty-text-details Les instructeurs de cette démarche n'ont pas encore fait appel aux experts.

View file

@ -425,10 +425,7 @@ Rails.application.routes.draw do
resources :administrateurs, controller: 'procedure_administrateurs', only: [:index, :create, :destroy]
resources :experts, controller: 'experts_procedures', only: [] do
post :add_expert_to_procedure, on: :collection
delete :revoke_expert_from_procedure, on: :member
end
resources :experts, controller: 'experts_procedures', only: [:create, :destroy]
resources :types_de_champ, only: [:create, :update, :destroy] do
member do

View file

@ -4,14 +4,17 @@ describe NewAdministrateur::ExpertsProceduresController, type: :controller do
before do
sign_in(admin.user)
end
describe '#add_expert_to_procedure' do
describe '#create' do
let(:procedure) { create :procedure, administrateur: admin }
let(:expert) { create(:expert) }
let(:expert2) { create(:expert) }
subject do
post :add_expert_to_procedure,
params: { procedure_id: procedure.id, emails: "[\"#{expert.email}\",\"#{expert2.email}\"]" }
post :create, params: {
procedure_id: procedure.id,
emails: "[\"#{expert.email}\",\"#{expert2.email}\"]"
}
end
before do
@ -26,13 +29,13 @@ describe NewAdministrateur::ExpertsProceduresController, type: :controller do
end
end
describe '#revoke_expert_from_procedure' do
describe '#delete' do
let(:procedure) { create :procedure, administrateur: admin }
let(:expert) { create(:expert) }
let(:expert_procedure) { ExpertsProcedure.create(expert: expert, procedure: procedure) }
subject do
delete :revoke_expert_from_procedure, params: { procedure_id: procedure.id, id: expert_procedure.id }
delete :destroy, params: { procedure_id: procedure.id, id: expert_procedure.id }
end
before do