allow other people to share with a user who ignores them
otherwise we have data-inconsistency if the user stops ignoring the person.
This commit is contained in:
parent
3dd2f2159c
commit
f4459488e5
2 changed files with 12 additions and 4 deletions
|
|
@ -118,7 +118,8 @@ class Contact < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_blocked_user
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,21 @@ describe Contact, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#not_blocked_user" do
|
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)
|
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).not_to be_valid
|
||||||
expect(bad_contact.errors.full_messages.count).to eq(1)
|
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")
|
expect(bad_contact.errors.full_messages.first).to eq("Cannot connect to an ignored user")
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue