added a fixed the pending request query

This commit is contained in:
zhitomirskiyi 2010-11-18 15:22:03 -08:00
parent c8c0b5c8a2
commit 0e171e8504
4 changed files with 20 additions and 2 deletions

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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