diff --git a/app/models/user/querying.rb b/app/models/user/querying.rb index 527712049..531c8f5fa 100644 --- a/app/models/user/querying.rb +++ b/app/models/user/querying.rb @@ -14,7 +14,7 @@ module User::Querying opts = prep_opts(klass, opts) shareable_ids = visible_shareable_ids(klass, opts) klass.where(id: shareable_ids).select("DISTINCT #{klass.table_name}.*") - .limit(opts[:limit]).order(opts[:order_with_table]).order(klass.table_name + ".id DESC") + .limit(opts[:limit]).order(opts[:order_with_table]) end def visible_shareable_ids(klass, opts={}) diff --git a/lib/diaspora/shareable.rb b/lib/diaspora/shareable.rb index 2548f5529..f0a5b3121 100644 --- a/lib/diaspora/shareable.rb +++ b/lib/diaspora/shareable.rb @@ -40,7 +40,7 @@ module Diaspora end def self.for_visible_shareable_sql(max_time, order, limit=15, types=Stream::Base::TYPES_OF_POST_IN_STREAM) - by_max_time(max_time, order).where(type: types).limit(limit) + by_max_time(max_time, order).order(table_name + ".id DESC").where(type: types).limit(limit) end def self.by_max_time(max_time, order="created_at") diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 308daa309..3a988f2a2 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -148,6 +148,22 @@ describe Post, :type => :model do Post.for_visible_shareable_sql(Time.now + 1, "created_at") end + context "with two posts with the same timestamp" do + before do + aspect_id = alice.aspects.where(name: "generic").first.id + Timecop.freeze Time.now do + alice.post(:status_message, text: "first", to: aspect_id) + alice.post(:status_message, text: "second", to: aspect_id) + end + end + + it "returns them in reverse creation order" do + posts = Post.for_visible_shareable_sql(Time.now + 1, "created_at") + expect(posts.first.text).to eq("second") + expect(posts.at(1).text).to eq("first") + expect(posts.last.text).to eq("alice - 5") + end + end end end end diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index c099476a1..6adebe002 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -113,21 +113,6 @@ describe User::Querying, :type => :model do expect(bob.visible_shareables(Post).count(:all)).to eq(0) end - context 'with two posts with the same timestamp' do - before do - aspect_id = alice.aspects.where(:name => "generic").first.id - Timecop.freeze Time.now do - alice.post :status_message, :text => "first", :to => aspect_id - alice.post :status_message, :text => "second", :to => aspect_id - end - end - - it "returns them in reverse creation order" do - expect(bob.visible_shareables(Post).first.text).to eq("second") - expect(bob.visible_shareables(Post).last.text).to eq("first") - end - end - context 'with many posts' do before do time_interval = 1000