tells if a user can be deleted
This commit is contained in:
parent
8d2d66a2b6
commit
58ef36ff57
2 changed files with 20 additions and 0 deletions
|
@ -96,6 +96,10 @@ class User < ApplicationRecord
|
|||
last_sign_in_at.present?
|
||||
end
|
||||
|
||||
def can_be_deleted?
|
||||
dossiers.state_instruction_commencee.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def link_invites!
|
||||
|
|
|
@ -209,4 +209,20 @@ describe User, type: :model do
|
|||
it { is_expected.to be true }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#can_be_deleted?' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
subject { user.can_be_deleted? }
|
||||
|
||||
context 'when the user has a dossier in instruction' do
|
||||
let!(:dossier) { create(:dossier, :en_instruction, user: user) }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context 'when the user has no dossier in instruction' do
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue