supprime un utilisateur qui a des dossiers cachés

This commit is contained in:
Christophe Robillard 2020-01-15 10:54:12 +01:00
parent 3f20925d66
commit d8a51f986f
2 changed files with 26 additions and 10 deletions

View file

@ -105,12 +105,11 @@ class User < ApplicationRecord
raise "Cannot delete this user because instruction has started for some dossiers"
end
if can_be_deleted?
dossiers.each do |dossier|
dossier.delete_and_keep_track(administration)
end
destroy
dossiers.each do |dossier|
dossier.delete_and_keep_track(administration)
end
dossiers.unscoped.destroy_all
destroy
end
private

View file

@ -241,12 +241,29 @@ describe User, type: :model do
let!(:dossier_en_construction) { create(:dossier, :en_construction, user: user) }
let!(:dossier_brouillon) { create(:dossier, user: user) }
it "keep track of dossiers and delete user" do
user.delete_and_keep_track_dossiers(administration)
context 'without a hidden dossier' do
it "keep track of dossiers and delete user" do
user.delete_and_keep_track_dossiers(administration)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_present
expect(User.find_by(id: user.id)).to be_nil
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_present
expect(User.find_by(id: user.id)).to be_nil
end
end
context 'with a hidden dossier' do
let!(:dossier_cache) do
create(:dossier, :en_construction, user: user)
end
it "keep track of dossiers and delete user" do
dossier_cache.delete_and_keep_track(administration)
user.delete_and_keep_track_dossiers(administration)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_present
expect(User.find_by(id: user.id)).to be_nil
end
end
end
end