Commit f4459488 authored by Benjamin Neff's avatar Benjamin Neff
Browse files

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
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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
+9 −2
Original line number Diff line number Diff line
@@ -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