From 85993a694eec033a5dd7eb882f2ba72caa67e7f5 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Wed, 13 Apr 2011 10:28:30 -0700 Subject: [PATCH] Fix people#show sort order --- app/controllers/people_controller.rb | 3 ++- spec/controllers/people_controller_spec.rb | 26 +++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index c6cae248b..97f0b7b8a 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -97,10 +97,11 @@ class PeopleController < ApplicationController @posts = current_user.posts_from(@person).where(:type => "StatusMessage").includes(:comments).limit(15).offset(15*(params[:page]-1)) else @commenting_disabled = true - @posts = @person.posts.where(:type => "StatusMessage", :public => true).includes(:comments).limit(15).offset(15*(params[:page]-1)) + @posts = @person.posts.where(:type => "StatusMessage", :public => true).includes(:comments).limit(15).offset(15*(params[:page]-1)).order('posts.created_at DESC') end @posts = PostsFake.new(@posts) + if params[:only_posts] render :partial => 'shared/stream', :locals => {:posts => @posts} else diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index a1624c16e..e38239a3b 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -154,16 +154,26 @@ describe PeopleController do response.should be_success end - it "assigns only public posts" do - public_posts = [] - public_posts << bob.post(:status_message, :text => "first public ", :to => bob.aspects[0].id, :public => true) - bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id) - bob.post(:status_message, :text => "to all aspects", :to => 'all') - public_posts << bob.post(:status_message, :text => "public", :to => 'all', :public => true) + context 'with posts' do + before do + @public_posts = [] + @public_posts << bob.post(:status_message, :text => "first public ", :to => bob.aspects[0].id, :public => true) + bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id) + bob.post(:status_message, :text => "to all aspects", :to => 'all') + @public_posts << bob.post(:status_message, :text => "public", :to => 'all', :public => true) + @public_posts.first.created_at -= 1000 + @public_posts.first.save + end - get :show, :id => @person.id + it "assigns only public posts" do + get :show, :id => @person.id + assigns[:posts].models.should =~ @public_posts + end - assigns[:posts].models.should =~ public_posts + it 'is sorted by created_at desc' do + get :show, :id => @person.id + assigns[:posts].models.should == @public_posts.sort_by{|p| p.created_at}.reverse + end end it 'throws 404 if the person is remote' do