Skip to content
Extraits de code Groupes Projets
Valider 72785a69 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Correct ordering problem in posts_from

parent 36781481
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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
......
......@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter