diff --git a/app/models/user/connecting.rb b/app/models/user/connecting.rb index 8b9da90d0..4ddd46e3e 100644 --- a/app/models/user/connecting.rb +++ b/app/models/user/connecting.rb @@ -34,6 +34,7 @@ class User logger.info "event=disconnect user=#{diaspora_handle} target=#{contact.person.diaspora_handle}" if contact.person.local? + raise "FATAL: user entry is missing from the DB. Aborting" if contact.person.owner.nil? contact.person.owner.disconnected_by(contact.user.person) else ContactRetraction.for(contact).defer_dispatch(self) diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index be4125cc4..c31ce1004 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -104,6 +104,16 @@ describe User::Connecting, type: :model do alice.disconnect(contact) }.to change(contact.aspects, :count).from(2).to(0) end + + it "raises when a contact for an improperly deleted user was passed" do + contact = alice.contact_for(bob.person) + + bob.delete + expect { + alice.disconnect(contact) + }.to raise_error "FATAL: user entry is missing from the DB. Aborting" + expect(Contact.where(id: contact.id)).to exist + end end end