don't select duplicate people
This commit is contained in:
parent
31e4683183
commit
a8306f9f37
2 changed files with 55 additions and 41 deletions
|
|
@ -27,14 +27,14 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def contacts
|
||||
t_p = Person.arel_table
|
||||
people = Person.arel_table
|
||||
incoming_aspects = Aspect.joins(:contacts).where(
|
||||
:user_id => self.person.owner_id,
|
||||
:contacts_visible => true,
|
||||
:contacts => {:person_id => self.user.person.id})
|
||||
:contacts => {:person_id => self.user.person.id}).select('`aspects`.id')
|
||||
incoming_aspect_ids = incoming_aspects.map{|a| a.id}
|
||||
similar_contacts = Person.joins(:contacts => :aspect_memberships).where(
|
||||
:aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(t_p[:id].not_eq(self.user.person.id))
|
||||
:aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(people[:id].not_eq(self.user.person.id)).select('DISTINCT `people`.*')
|
||||
end
|
||||
private
|
||||
def not_contact_for_self
|
||||
|
|
|
|||
|
|
@ -47,17 +47,6 @@ describe Contact do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
context 'requesting' do
|
||||
before do
|
||||
@contact = Contact.new
|
||||
@user = Factory.create(:user)
|
||||
@person = Factory(:person)
|
||||
|
||||
@contact.user = @user
|
||||
@contact.person = @person
|
||||
end
|
||||
|
||||
describe '#contacts' do
|
||||
before do
|
||||
@alice = alice
|
||||
|
|
@ -92,8 +81,33 @@ describe Contact do
|
|||
asp.save
|
||||
@contact.contacts.should == []
|
||||
end
|
||||
it 'returns no duplicate contacts' do
|
||||
[@alice, @eve].each {|c| @bob.add_contact_to_aspect(@bob.contact_for(c.person), @bob.aspects.last)}
|
||||
contact_ids = @contact.contacts.map{|p| p.id}
|
||||
contact_ids.uniq.should == contact_ids
|
||||
end
|
||||
end
|
||||
|
||||
context 'on a contact for a remote user' do
|
||||
before do
|
||||
@contact = @bob.contact_for @people1.first
|
||||
end
|
||||
it 'returns an empty array' do
|
||||
@contact.contacts.should == []
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
context 'requesting' do
|
||||
before do
|
||||
@contact = Contact.new
|
||||
@user = Factory.create(:user)
|
||||
@person = Factory(:person)
|
||||
|
||||
@contact.user = @user
|
||||
@contact.person = @person
|
||||
end
|
||||
|
||||
describe '#generate_request' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue