diff --git a/app/controllers/manager/administrateurs_controller.rb b/app/controllers/manager/administrateurs_controller.rb index 83894c0ab..74bd191ea 100644 --- a/app/controllers/manager/administrateurs_controller.rb +++ b/app/controllers/manager/administrateurs_controller.rb @@ -42,7 +42,7 @@ module Manager administrateur.dossiers.each(&:delete_and_keep_track) administrateur.destroy - logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_user.id}") + logger.info("L'administrateur #{administrateur.id} est supprimé par #{current_administration.id}") flash[:notice] = "L'administrateur #{administrateur.id} est supprimé" redirect_to manager_administrateurs_path diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 9a9f39174..dffe94034 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -8,7 +8,7 @@ class Administrateur < ApplicationRecord has_many :services has_many :dossiers, -> { state_not_brouillon }, through: :procedures - has_one :user + has_one :user, dependent: :nullify before_validation -> { sanitize_email(:email) } diff --git a/spec/controllers/manager/administrateurs_controller_spec.rb b/spec/controllers/manager/administrateurs_controller_spec.rb index f7b9a11e9..0d954ee3c 100644 --- a/spec/controllers/manager/administrateurs_controller_spec.rb +++ b/spec/controllers/manager/administrateurs_controller_spec.rb @@ -31,4 +31,18 @@ describe Manager::AdministrateursController, type: :controller do it { expect { subject }.to change(Administrateur, :count).by(0) } end end + + describe '#delete' do + let!(:admin) { create(:administrateur) } + + before { sign_in administration } + + subject { delete :delete, params: { id: admin.id } } + + it 'deletes the admin' do + subject + + expect(Administrateur.find_by(id: admin.id)).to be_nil + end + end end