Correct erratic spec failure

This commit is contained in:
Sam 2017-08-17 15:26:31 -04:00
parent 0c4527323e
commit c2a6616035
2 changed files with 9 additions and 3 deletions

View File

@ -23,7 +23,13 @@ class CategoryFeaturedTopic < ActiveRecord::Base
no_definitions: true
}
# Add topics, even if they're in secured categories:
# It may seem a bit odd that we are running 2 queries here, when admin
# can clearly pull out all the topics needed.
# We do so, so anonymous will ALWAYS get some topics
# If we only fetched as admin we may have a situation where anon can see
# no featured topics (all the previous 2x topics are only visible to admins)
# Add topics, even if they're in secured categories or invisible
query = TopicQuery.new(CategoryFeaturedTopic.fake_admin, query_opts)
results = query.list_category_topic_ids(c).uniq

View File

@ -34,7 +34,7 @@ describe CategoryFeaturedTopic do
it 'should feature stuff in the correct order' do
category = Fabricate(:category, num_featured_topics: 2)
t5 = Fabricate(:topic, category_id: category.id, bumped_at: 12.minutes.ago)
_t5 = Fabricate(:topic, category_id: category.id, bumped_at: 12.minutes.ago)
t4 = Fabricate(:topic, category_id: category.id, bumped_at: 10.minutes.ago)
t3 = Fabricate(:topic, category_id: category.id, bumped_at: 7.minutes.ago)
t2 = Fabricate(:topic, category_id: category.id, bumped_at: 4.minutes.ago)
@ -45,7 +45,7 @@ describe CategoryFeaturedTopic do
# Should find more than we need: pinned topics first, then num_featured_topics * 2
expect(
CategoryFeaturedTopic.where(category_id: category.id).pluck(:topic_id)
CategoryFeaturedTopic.where(category_id: category.id).order('rank asc').pluck(:topic_id)
).to eq([pinned.id, t2.id, t1.id, t3.id, t4.id])
end