Fix PeopleController, add specs

This commit is contained in:
Raphael 2010-11-27 21:46:07 -05:00
parent 1ec1ada70b
commit d2bfffca92
3 changed files with 30 additions and 1 deletions

View file

@ -39,6 +39,7 @@ class PeopleController < ApplicationController
end
@posts = current_user.visible_posts(:person_id => @person.id, :_type => "StatusMessage").paginate :page => params[:page], :order => 'created_at DESC'
@post_hashes = hashes_for_posts @posts
respond_with @person, :locals => {:post_type => :all}
else
@ -100,6 +101,21 @@ class PeopleController < ApplicationController
end
private
def hashes_for_posts posts
comment_hash = Comment.hash_from_post_ids posts.map{|p| p.id}
person_hash = Person.from_post_comment_hash comment_hash
posts.map do |post|
{:post => post,
:person => @person,
:comments => comment_hash[post.id].map do |comment|
{:comment => comment,
:person => person_hash[comment.person_id],
}
end,
}
end
end
def webfinger(account, opts = {})
finger = EMWebfinger.new(account)
finger.on_person do |response|

View file

@ -26,7 +26,7 @@
-if @post_type == :photos
= render 'photos/index', :photos => @posts
- else
= render 'shared/stream', :posts => @posts
= render 'shared/stream', :posts => @post_hashes
= will_paginate @posts
- else

View file

@ -57,6 +57,19 @@ describe PeopleController do
response.should be_success
end
it 'renders with a post' do
user.post :status_message, :message => 'test more', :to => aspect.id
get :show, :id => user.person.id
response.should be_success
end
it 'renders with a post' do
message = user.post :status_message, :message => 'test more', :to => aspect.id
user.comment 'I mean it', :on => message
get :show, :id => user.person.id
response.should be_success
end
it "redirects on an invalid id" do
get :show, :id => 'delicious'
response.should redirect_to people_path