Merge pull request #4889 from betagouv/4888-fix-suppression-administrateur
remove orphan services when destroying administrateur
This commit is contained in:
commit
b4058e85eb
2 changed files with 13 additions and 0 deletions
|
@ -85,6 +85,11 @@ class Administrateur < ApplicationRecord
|
|||
next_administrateur = procedure.administrateurs.where.not(id: self.id).first
|
||||
procedure.service.update(administrateur: next_administrateur)
|
||||
end
|
||||
|
||||
services.each do |service|
|
||||
service.destroy unless service.procedures.any?
|
||||
end
|
||||
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,6 +59,14 @@ describe Administrateur, type: :model do
|
|||
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
||||
expect(service.reload.administrateur).to eq(autre_administrateur)
|
||||
end
|
||||
|
||||
it "delete service if not associated to procedures" do
|
||||
service_without_procedure = create(:service, administrateur: administrateur)
|
||||
administrateur.delete_and_transfer_services
|
||||
|
||||
expect(Service.find_by(id: service_without_procedure.id)).to be_nil
|
||||
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
# describe '#password_complexity' do
|
||||
|
|
Loading…
Reference in a new issue