From e4ad229a5a0d894904ecc218e766cb60395a78d9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 25 Jan 2011 18:23:54 -0800 Subject: [PATCH] Requestors are now high in search --- app/models/person.rb | 3 ++- spec/models/person_spec.rb | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 9289703e5..2b31e6eb8 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -67,7 +67,8 @@ class Person < ActiveRecord::Base # ORDER BY `contacts`.user_id DESC Person.searchable.where(sql, *tokens).joins( "LEFT OUTER JOIN `contacts` ON `contacts`.user_id = #{user.id} AND `contacts`.person_id = `people`.id" - ).order("contacts.user_id DESC", "profiles.last_name ASC", "profiles.first_name ASC", "people.diaspora_handle ASC") + ).joins("LEFT OUTER JOIN `requests` ON `requests`.recipient_id = #{user.person.id} AND `requests`.sender_id = `people`.id" + ).order("contacts.user_id DESC", "requests.recipient_id DESC", "profiles.last_name ASC", "profiles.first_name ASC") end def name diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 08cfd787e..31ea2da2b 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -152,6 +152,12 @@ describe Person do describe '.search' do before do Person.delete_all + @user = Factory.create(:user_with_aspect) + user_profile = @user.person.profile + user_profile.first_name = "aiofj" + user_profile.last_name = "asdji" + user_profile.save + @robert_grimm = Factory.create(:searchable_person) @eugene_weinstein = Factory.create(:searchable_person) @yevgeniy_dodis = Factory.create(:searchable_person) @@ -224,11 +230,22 @@ describe Person do people.should == [@robert_grimm] end - it 'orders by whether the person is friends with the searching user' do + it "puts the searching user's contacts first" do @user.activate_contact(@casey_grippi, @user.aspects.first) people = Person.search("ing", @user) people.map{|p| p.name}.should == [@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map{|p|p.name} end + it "puts the searching user's incoming requests first" do + requestor = Factory(:user_with_aspect) + profile = requestor.person.profile + profile.first_name = "Requesting" + profile.last_name = "Something" + profile.save + + requestor.send_contact_request_to(@user.person, requestor.aspects.first) + people = Person.search("ing", @user) + people.map{|p| p.name}.should == [requestor.person, @yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map{|p|p.name} + end end context 'people finders for webfinger' do