diff --git a/app/models/user/connecting.rb b/app/models/user/connecting.rb index 8b9da90d022fb9dbab367962454e7513c90260a8..4ddd46e3ed56e311376875c4284939ec7d421efc 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 be4125cc470ed4fb1c772938d9951c4f4d232d8f..c31ce1004f7948f7af3bfbf906300b534dfd538f 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