Skip to content
Extraits de code Groupes Projets
Valider 83103c47 rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

deterministic stream order take 2, this time with spec

parent d767410e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -16,7 +16,7 @@ module User::Querying ...@@ -16,7 +16,7 @@ module User::Querying
def visible_shareables(klass, opts={}) def visible_shareables(klass, opts={})
opts = prep_opts(klass, opts) opts = prep_opts(klass, opts)
shareable_ids = visible_shareable_ids(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 end
def visible_shareable_ids(klass, opts={}) def visible_shareable_ids(klass, opts={})
...@@ -48,7 +48,7 @@ module User::Querying ...@@ -48,7 +48,7 @@ module User::Querying
def ugly_select_clause(query, opts) def ugly_select_clause(query, opts)
klass = opts[:klass] 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] 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 end
def construct_shareable_from_others_query(opts) def construct_shareable_from_others_query(opts)
......
...@@ -113,6 +113,21 @@ describe User::Querying do ...@@ -113,6 +113,21 @@ describe User::Querying do
Factory(:status_message, :public => true) Factory(:status_message, :public => true)
bob.visible_shareables(Post).count.should == 0 bob.visible_shareables(Post).count.should == 0
end 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 context 'with many posts' do
before do before do
......
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