From 062f52feb9be64debe6d6f2a732fe606cd97a65a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 5 Jan 2022 15:21:59 +0000 Subject: [PATCH] Fix ProcedureAdministrateursController#destroy - The "no remove oneself" rule wasn't actually enforced - `flash.error` is not a flash category --- .../procedure_administrateurs_controller.rb | 3 ++- .../procedure_administrateurs_controller_spec.rb | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/administrateurs/procedure_administrateurs_controller.rb b/app/controllers/administrateurs/procedure_administrateurs_controller.rb index c03c5c4a9..3bc56f546 100644 --- a/app/controllers/administrateurs/procedure_administrateurs_controller.rb +++ b/app/controllers/administrateurs/procedure_administrateurs_controller.rb @@ -32,7 +32,8 @@ module Administrateurs # Prevent self-removal (Also enforced in the UI) if administrateur == current_administrateur - flash.error = "Vous ne pouvez pas vous retirer vous-même d’une démarche." + flash.alert = "Vous ne pouvez pas vous retirer vous-même d’une démarche." + return end # Actually remove the admin diff --git a/spec/controllers/administrateurs/procedure_administrateurs_controller_spec.rb b/spec/controllers/administrateurs/procedure_administrateurs_controller_spec.rb index bbec91374..2094a8d54 100644 --- a/spec/controllers/administrateurs/procedure_administrateurs_controller_spec.rb +++ b/spec/controllers/administrateurs/procedure_administrateurs_controller_spec.rb @@ -18,8 +18,19 @@ describe Administrateurs::ProcedureAdministrateursController, type: :controller it 'removes the admin from the procedure' do subject expect(response.status).to eq(200) - expect(signed_in_admin.procedures.reload).to include(procedure) - expect(other_admin.procedures.reload).not_to include(procedure) + expect(flash[:notice]).to be_present + expect(admin_to_remove.procedures.reload).not_to include(procedure) + end + end + + context 'when removing oneself from a procedure' do + let(:admin_to_remove) { signed_in_admin } + + it 'denies the right for an admin to remove itself' do + subject + expect(response.status).to eq(200) + expect(flash[:alert]).to be_present + expect(admin_to_remove.procedures.reload).to include(procedure) end end end