diff --git a/app/models/contact.rb b/app/models/contact.rb index a4025ad1a..272e5cb91 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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 - diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index a1fa9e750..db7bd71b0 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -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