diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 1b10ef424..dec2524ba 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -36,7 +36,7 @@ class PeopleController < ApplicationController if @contact @aspects_with_person = @contact.aspects else - @pending_request = current_user.pending_requests.find_by_person_id(@person.id) + @pending_request = current_user.request_for(@person) end @posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml index b0c94bbe3..5afce753f 100644 --- a/app/views/people/_person.html.haml +++ b/app/views/people/_person.html.haml @@ -15,7 +15,7 @@ = t('.thats_you') - elsif current_user.person_objects.include?(person) = t('.already_connected') - - elsif current_user.pending_requests.find_by_person_id(person.id) + - elsif current_user.request_for(person) = link_to =t('.pending_request'), aspects_manage_path - else - single_aspect_form ||= nil diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index c864c4908..1f7718f50 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -84,6 +84,9 @@ module Diaspora self.aspects.all.collect{|x| x.id} end + def request_for(to_person) + Request.first(:from_id => self.person.id, :to_id => to_person.id).first + end end end end diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index e981b436e..c6ab423cc 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -173,4 +173,19 @@ describe User do end end + describe "#request_for" do + let!(:user5) {make_user} + + it 'should not have a pending request before connecting' do + request = user.request_for(user5.person) + request.should be_nil + end + + it 'should have a pending request after sending a request' do + user.send_contact_request_to(user5.person, user.aspects.first) + request = user.reload.request_for(user5.person) + request.should_not be_nil + end + end + end