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