Check for user existence on aspect membership destruction

This commit is contained in:
cmrd Senya 2017-10-01 03:05:57 +03:00 committed by Benjamin Neff
parent a36d22d72b
commit f212b51f7f
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
2 changed files with 9 additions and 3 deletions

View file

@ -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

View file

@ -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