Fix admin deletion by an administration

This commit is contained in:
simon lehericey 2019-08-19 10:47:37 +02:00
parent 6e83f3d524
commit ebe871819d
3 changed files with 16 additions and 2 deletions

View file

@ -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

View file

@ -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) }

View file

@ -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