From d2bfffca9248ec0fbd2e4b0ec1e3e8b9c060c289 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Sat, 27 Nov 2010 21:46:07 -0500 Subject: [PATCH] Fix PeopleController, add specs --- app/controllers/people_controller.rb | 16 ++++++++++++++++ app/views/people/show.html.haml | 2 +- spec/controllers/people_controller_spec.rb | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 64a00becd8..f024e791c3 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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| diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 3f0e8ec318..27ac84168b 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -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 diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index d3b5a909f1..0824652dcb 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -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 -- GitLab