From ddfc558a9b5d6ed19e89b7a6ad9ecf0dc4ebb8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Sat, 16 Feb 2013 23:22:14 +0100 Subject: [PATCH] fix regression from #3968 Not ordering the IDs caused incorret ones returned The spec is totally at the wrong level but I couldn't make something up that exposed the bug at a deeper level :( --- lib/evil_query.rb | 4 ++-- spec/lib/stream/person_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/evil_query.rb b/lib/evil_query.rb index bb04d251d..13df0b981 100644 --- a/lib/evil_query.rb +++ b/lib/evil_query.rb @@ -139,11 +139,11 @@ module EvilQuery end def persons_private_visibilities - contact.share_visibilities.where(:hidden => false, :shareable_type => @class.to_s).limit(15) + contact.share_visibilities.where(:hidden => false, :shareable_type => @class.to_s).order("created_at DESC").limit(15) end def persons_public_posts - @person.send(table_name).where(:public => true).select(table_name + '.id').limit(15) + @person.send(table_name).where(:public => true).select(table_name + '.id').order("created_at DESC").limit(15) end end end diff --git a/spec/lib/stream/person_spec.rb b/spec/lib/stream/person_spec.rb index 344e8c4ef..ddc69a5e4 100644 --- a/spec/lib/stream/person_spec.rb +++ b/spec/lib/stream/person_spec.rb @@ -9,4 +9,24 @@ describe Stream::Person do describe 'shared behaviors' do it_should_behave_like 'it is a stream' end + + it "returns the most recent posts" do + posts = [] + fetched_posts = [] + + aspect = bob.aspects.first.id + Timecop.scale(600) do + 16.times do |n| + posts << bob.post(:status_message, text: "hello#{n}", to: aspect) + posts << bob.post(:status_message, text: "hello#{n}", public: true) + end + + fetched_posts = Stream::Person.new(alice, bob.person).stream_posts + end + + posts = posts.reverse.slice(0..14) + fetched_posts = fetched_posts.slice(0..14) + + fetched_posts.should == posts + end end