Check for user existence on aspect membership destruction
This commit is contained in:
parent
a36d22d72b
commit
f212b51f7f
2 changed files with 9 additions and 3 deletions
|
|
@ -11,9 +11,7 @@ class AspectMembership < ApplicationRecord
|
|||
has_one :person, :through => :contact
|
||||
|
||||
before_destroy do
|
||||
if self.contact && self.contact.aspects.size == 1
|
||||
self.user.disconnect(self.contact)
|
||||
end
|
||||
user&.disconnect(contact) if contact&.aspects&.size == 1
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -26,5 +26,13 @@ describe AspectMembership, :type => :model do
|
|||
alice.add_contact_to_aspect(contact, aspect)
|
||||
aspect_membership.destroy
|
||||
end
|
||||
|
||||
it "doesn't fail destruction if the user entry was deleted in prior" do
|
||||
aspect_membership.user.delete
|
||||
id = aspect_membership.id
|
||||
|
||||
expect { AspectMembership.find(id).destroy }.not_to raise_error
|
||||
expect(AspectMembership.where(id: id)).not_to exist
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue