Correct ordering problem in posts_from

This commit is contained in:
Raphael 2011-01-17 12:21:38 -08:00
parent 36781481bb
commit 72785a69cb
2 changed files with 18 additions and 9 deletions

View file

@ -70,10 +70,9 @@ module Diaspora
end
def posts_from(person)
public_posts = person.posts.where(:public => true)
directed_posts = raw_visible_posts.where(:person_id => person.id)
posts = public_posts | directed_posts
posts.sort!{|p1,p2| p1.created_at <=> p2.created_at }
asp = Aspect.arel_table
p = Post.arel_table
Post.joins(:aspects).where( p[:public].eq(true).or(asp[:user_id].eq(self.id))).order("updated_at DESC")
end
end
end

View file

@ -213,12 +213,11 @@ describe User do
describe '#posts_from' do
before do
@user3 = Factory(:user)
@aspect3 = @user3.aspects.create(:name => "bros")
@user3 = Factory(:user)
@aspect3 = @user3.aspects.create(:name => "bros")
@public_message = @user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)
@private_message = @user3.post(:status_message, :message => "hey there", :to => @aspect3.id)
@public_message = @user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)
@private_message = @user3.post(:status_message, :message => "hey there", :to => @aspect3.id)
end
it 'displays public posts for a non-contact' do
@ -238,5 +237,16 @@ describe User do
@user.posts_from(@user3.person).should include @public_message
@user.posts_from(@user3.person).should include new_message
end
it 'displays recent posts first' do
msg3 = @user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)
msg4 = @user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)
msg3.updated_at = Time.now+10
msg3.save!
msg4.updated_at = Time.now+14
msg4.save!
@user.posts_from(@user3.person).map{|p| p.id}.should == [msg4, msg3, @public_message].map{|p| p.id}
end
end
end