Commit f4459488 authored by Benjamin Neff's avatar Benjamin Neff

allow other people to share with a user who ignores them

otherwise we have data-inconsistency if the user stops ignoring the
person.
parent 3dd2f215
......@@ -118,7 +118,8 @@ class Contact < ActiveRecord::Base
end
def not_blocked_user
errors.add(:base, "Cannot connect to an ignored user") if user && user.blocks.where(person_id: person_id).exists?
if receiving && user && user.blocks.where(person_id: person_id).exists?
errors.add(:base, "Cannot connect to an ignored user")
end
end
end
......@@ -62,14 +62,21 @@ describe Contact, type: :model do
end
describe "#not_blocked_user" do
it "add error if potential contact is blocked by user" do
it "adds an error when start sharing with a blocked person" do
alice.blocks.create(person: eve.person)
bad_contact = alice.contacts.create(person: eve.person)
bad_contact = alice.contacts.create(person: eve.person, receiving: true)
expect(bad_contact).not_to be_valid
expect(bad_contact.errors.full_messages.count).to eq(1)
expect(bad_contact.errors.full_messages.first).to eq("Cannot connect to an ignored user")
end
it "is valid when a blocked person starts sharing with the user" do
alice.blocks.create(person: eve.person)
bad_contact = alice.contacts.create(person: eve.person, receiving: false, sharing: true)
expect(bad_contact).to be_valid
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment