Fix admin deletion by an administration
This commit is contained in:
parent
6e83f3d524
commit
ebe871819d
3 changed files with 16 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue