fix admin deletion of empty service with archived procedures
This commit is contained in:
parent
5e1e11d802
commit
8c2f589cbf
2 changed files with 12 additions and 2 deletions
|
@ -81,13 +81,14 @@ class Administrateur < ApplicationRecord
|
||||||
fail "Impossible de supprimer cet administrateur car il a des démarches où il est le seul administrateur"
|
fail "Impossible de supprimer cet administrateur car il a des démarches où il est le seul administrateur"
|
||||||
end
|
end
|
||||||
|
|
||||||
procedures.each do |procedure|
|
procedures.with_discarded.each do |procedure|
|
||||||
next_administrateur = procedure.administrateurs.where.not(id: self.id).first
|
next_administrateur = procedure.administrateurs.where.not(id: self.id).first
|
||||||
procedure.service.update(administrateur: next_administrateur)
|
procedure.service.update(administrateur: next_administrateur)
|
||||||
end
|
end
|
||||||
|
|
||||||
services.each do |service|
|
services.each do |service|
|
||||||
service.destroy unless service.procedures.any?
|
# We can't destroy a service if it has procedures, even if those procedures are archived
|
||||||
|
service.destroy unless service.procedures.with_discarded.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
destroy
|
destroy
|
||||||
|
|
|
@ -65,6 +65,15 @@ describe Administrateur, type: :model do
|
||||||
expect(Service.find_by(id: service_without_procedure.id)).to be_nil
|
expect(Service.find_by(id: service_without_procedure.id)).to be_nil
|
||||||
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not delete service if associated to an archived procedure" do
|
||||||
|
service.update(administrateur: administrateur)
|
||||||
|
procedure.discard!
|
||||||
|
administrateur.delete_and_transfer_services
|
||||||
|
|
||||||
|
expect(Service.find_by(id: procedure.service.id)).not_to be_nil
|
||||||
|
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# describe '#password_complexity' do
|
# describe '#password_complexity' do
|
||||||
|
|
Loading…
Reference in a new issue