destroys not all dossiers

but only dossiers for a specific user
This commit is contained in:
Christophe Robillard 2020-01-30 11:18:01 +01:00
parent cee4c5b8fb
commit 6fc8a27bd7
2 changed files with 11 additions and 1 deletions

View file

@ -108,7 +108,7 @@ class User < ApplicationRecord
dossiers.each do |dossier|
dossier.delete_and_keep_track(administration)
end
dossiers.unscoped.destroy_all
dossiers.with_hidden.destroy_all
destroy!
end

View file

@ -273,6 +273,9 @@ describe User, type: :model do
let!(:dossier_cache) do
create(:dossier, :en_construction, user: user)
end
let!(:dossier_from_another_user) do
create(:dossier, :en_construction, user: create(:user))
end
it "keep track of dossiers and delete user" do
dossier_cache.delete_and_keep_track(administration)
@ -282,6 +285,13 @@ describe User, type: :model do
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_present
expect(User.find_by(id: user.id)).to be_nil
end
it "doesn't destroy dossiers of another user" do
dossier_cache.delete_and_keep_track(administration)
user.delete_and_keep_track_dossiers(administration)
expect(Dossier.find_by(id: dossier_from_another_user.id)).not_to be_nil
end
end
end
end