Raise sensible error message when user is missing

That's for the case when podmin has messed up the database
This commit is contained in:
cmrd Senya 2017-10-01 04:22:20 +03:00 committed by Benjamin Neff
parent f212b51f7f
commit 973e9d98c6
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
2 changed files with 11 additions and 0 deletions

View file

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

View file

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