From 7021cd79c85691c8ff27e8836d9bce614844c33c Mon Sep 17 00:00:00 2001 From: Raphael Sofaer <raphael@joindiaspora.com> Date: Thu, 11 Aug 2011 11:56:23 -0700 Subject: [PATCH] Select distinct people in contacts index --- app/controllers/contacts_controller.rb | 1 + spec/controllers/contacts_controller_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index c87aeec930..6ec8d65db0 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -25,6 +25,7 @@ class ContactsController < ApplicationController format.mobile { @contacts = sort_and_paginate_profiles(@contacts) } format.json { @people = Person.joins(:contacts => :aspect_memberships). + select('DISTINCT people.*'). where(:contacts => { :user_id => current_user.id }, :aspect_memberships => { :aspect_id => params[:aspect_ids] }) diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index dfdff97a20..a0b00d5ca6 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -67,6 +67,14 @@ describe ContactsController do get :index save_fixture(html_for("body"), "aspects_manage") end + + it 'does not select duplicate contacts' do + aspect = bob.aspects.create(:name => 'hilarious people') + aspect.contacts << bob.contact_for(eve.person) + get :index, :format => 'json', :aspect_ids => bob.aspect_ids + assigns[:people].map{|p| p.id}.uniq.should == assigns[:people].map{|p| p.id} + assigns[:people].should == bob.contacts.map(&:person) + end end describe '#featured' do -- GitLab