raise if trying to del a user who can't be deleted
This commit is contained in:
parent
696a058280
commit
0f881f942b
3 changed files with 6 additions and 9 deletions
|
@ -101,6 +101,10 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_and_keep_track_dossiers(administration)
|
def delete_and_keep_track_dossiers(administration)
|
||||||
|
if !can_be_deleted?
|
||||||
|
raise "Cannot delete this user because instruction has started for some dossiers"
|
||||||
|
end
|
||||||
|
|
||||||
if can_be_deleted?
|
if can_be_deleted?
|
||||||
dossiers.each do |dossier|
|
dossiers.each do |dossier|
|
||||||
dossier.delete_and_keep_track(administration)
|
dossier.delete_and_keep_track(administration)
|
||||||
|
|
|
@ -15,10 +15,6 @@ namespace :support do
|
||||||
user = User.find_by!(email: user_email)
|
user = User.find_by!(email: user_email)
|
||||||
administration = Administration.find_by!(email: administration_email)
|
administration = Administration.find_by!(email: administration_email)
|
||||||
|
|
||||||
if !user.can_be_deleted?
|
|
||||||
fail "Cannot delete this user because instruction has started for some dossiers"
|
|
||||||
end
|
|
||||||
|
|
||||||
user.delete_and_keep_track_dossiers(administration)
|
user.delete_and_keep_track_dossiers(administration)
|
||||||
user.destroy
|
user.destroy
|
||||||
end
|
end
|
||||||
|
|
|
@ -232,11 +232,8 @@ describe User, type: :model do
|
||||||
|
|
||||||
context 'avec un dossier en instruction' do
|
context 'avec un dossier en instruction' do
|
||||||
let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) }
|
let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) }
|
||||||
it 'ne supprime rien si dossier en instruction' do
|
it 'raises' do
|
||||||
user.delete_and_keep_track_dossiers(administration)
|
expect { user.delete_and_keep_track_dossiers(administration) }.to raise_error
|
||||||
|
|
||||||
expect(Dossier.find_by(id: dossier_en_instruction.id)).to be_present
|
|
||||||
expect(User.find_by(id: user.id)).to be_present
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue