deterministic stream order take 2, this time with spec
This commit is contained in:
parent
d767410e6d
commit
83103c4761
2 changed files with 17 additions and 2 deletions
|
|
@ -16,7 +16,7 @@ module User::Querying
|
|||
def visible_shareables(klass, opts={})
|
||||
opts = prep_opts(klass, opts)
|
||||
shareable_ids = visible_shareable_ids(klass, opts)
|
||||
klass.where(:id => shareable_ids).select('DISTINCT '+klass.to_s.tableize+'.*').limit(opts[:limit]).order(opts[:order_with_table])
|
||||
klass.where(:id => shareable_ids).select('DISTINCT '+klass.to_s.tableize+'.*').limit(opts[:limit]).order(opts[:order_with_table]).order(klass.table_name+".id DESC")
|
||||
end
|
||||
|
||||
def visible_shareable_ids(klass, opts={})
|
||||
|
|
@ -48,7 +48,7 @@ module User::Querying
|
|||
def ugly_select_clause(query, opts)
|
||||
klass = opts[:klass]
|
||||
select_clause ='DISTINCT %s.id, %s.updated_at AS updated_at, %s.created_at AS created_at' % [klass.table_name, klass.table_name, klass.table_name]
|
||||
query.select(select_clause).order(opts[:order_with_table]).order(klass.table_name+'.id DESC').where(klass.arel_table[opts[:order_field]].lt(opts[:max_time]))
|
||||
query.select(select_clause).order(opts[:order_with_table]).where(klass.arel_table[opts[:order_field]].lt(opts[:max_time]))
|
||||
end
|
||||
|
||||
def construct_shareable_from_others_query(opts)
|
||||
|
|
|
|||
|
|
@ -113,6 +113,21 @@ describe User::Querying do
|
|||
Factory(:status_message, :public => true)
|
||||
bob.visible_shareables(Post).count.should == 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
|
||||
bob.visible_shareables(Post).first.text.should == "second"
|
||||
bob.visible_shareables(Post).last.text.should == "first"
|
||||
end
|
||||
end
|
||||
|
||||
context 'with many posts' do
|
||||
before do
|
||||
|
|
|
|||
Loading…
Reference in a new issue