REGRESSION: incorrect ordering when featuring topics
This commit is contained in:
parent
fe578f9944
commit
3658c21fc5
|
@ -132,7 +132,11 @@ class TopicQuery
|
|||
end
|
||||
|
||||
def list_category_topic_ids(category)
|
||||
default_results(unordered: true, category: category.id).pluck(:id)
|
||||
query = default_results(category: category.id)
|
||||
pinned_ids = query.where('pinned_at IS NOT NULL').order('pinned_at DESC').pluck(:id)
|
||||
non_pinned_ids = query.where('pinned_at IS NULL').pluck(:id)
|
||||
|
||||
(pinned_ids + non_pinned_ids)[0...@options[:per_page]]
|
||||
end
|
||||
|
||||
def list_new_in_category(category)
|
||||
|
|
|
@ -31,6 +31,23 @@ describe CategoryFeaturedTopic do
|
|||
CategoryFeaturedTopic.feature_topics_for(category)
|
||||
expect(CategoryFeaturedTopic.count).to be(1)
|
||||
end
|
||||
|
||||
|
||||
it 'should feature stuff in the correct order' do
|
||||
|
||||
category = Fabricate(:category)
|
||||
_t3 = Fabricate(:topic, category_id: category.id, bumped_at: 7.minutes.ago)
|
||||
t2 = Fabricate(:topic, category_id: category.id, bumped_at: 4.minutes.ago)
|
||||
t1 = Fabricate(:topic, category_id: category.id, bumped_at: 5.minutes.ago)
|
||||
pinned = Fabricate(:topic, category_id: category.id, pinned_at: 10.minutes.ago, bumped_at: 10.minutes.ago)
|
||||
|
||||
CategoryFeaturedTopic.feature_topics_for(category)
|
||||
|
||||
expect(
|
||||
CategoryFeaturedTopic.where(category_id: category.id).pluck(:topic_id)
|
||||
).to eq([pinned.id, t2.id, t1.id])
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue