correct spec failure, only test code was affected

This commit is contained in:
Sam 2015-03-03 10:20:42 +11:00
parent 33df000bb7
commit f432b9f5b7
3 changed files with 17 additions and 12 deletions

View file

@ -72,6 +72,7 @@ class RandomTopicSelector
Category.select(:id).each do |c| Category.select(:id).each do |c|
$redis.del cache_key(c) $redis.del cache_key(c)
end end
$redis.del cache_key
end end
def self.cache_key(category=nil) def self.cache_key(category=nil)

View file

@ -425,7 +425,7 @@ class TopicQuery
max = (count*1.3).to_i max = (count*1.3).to_i
ids = RandomTopicSelector.next(max) + RandomTopicSelector.next(max, topic.category) ids = RandomTopicSelector.next(max) + RandomTopicSelector.next(max, topic.category)
result.where(id: ids) result.where(id: ids.uniq)
end end
def suggested_ordering(result, options) def suggested_ordering(result, options)

View file

@ -432,6 +432,10 @@ describe TopicQuery do
context 'when logged in' do context 'when logged in' do
before do
RandomTopicSelector.clear_cache!
end
let(:topic) { Fabricate(:topic) } let(:topic) { Fabricate(:topic) }
let(:suggested_topics) { topic_query.list_suggested_for(topic).topics.map{|t| t.id} } let(:suggested_topics) { topic_query.list_suggested_for(topic).topics.map{|t| t.id} }
@ -450,7 +454,6 @@ describe TopicQuery do
let!(:fully_read_archived) { Fabricate(:post, user: creator).topic } let!(:fully_read_archived) { Fabricate(:post, user: creator).topic }
before do before do
RandomTopicSelector.clear_cache!
user.auto_track_topics_after_msecs = 0 user.auto_track_topics_after_msecs = 0
user.save user.save
TopicUser.update_last_read(user, partially_read.id, 0, 0) TopicUser.update_last_read(user, partially_read.id, 0, 0)
@ -463,6 +466,17 @@ describe TopicQuery do
fully_read_archived.save fully_read_archived.save
end end
it "returns unread, then new, then random" do
SiteSetting.suggested_topics = 7
expect(suggested_topics[0]).to eq(partially_read.id)
expect(suggested_topics[1,3]).to include(new_topic.id)
expect(suggested_topics[1,3]).to include(closed_topic.id)
expect(suggested_topics[1,3]).to include(archived_topic.id)
expect(suggested_topics[4]).to eq(fully_read.id)
# random doesn't include closed and archived
end
it "won't return new or fully read if there are enough partially read topics" do it "won't return new or fully read if there are enough partially read topics" do
SiteSetting.suggested_topics = 1 SiteSetting.suggested_topics = 1
expect(suggested_topics).to eq([partially_read.id]) expect(suggested_topics).to eq([partially_read.id])
@ -476,16 +490,6 @@ describe TopicQuery do
expect(suggested_topics[1,3]).to include(archived_topic.id) expect(suggested_topics[1,3]).to include(archived_topic.id)
end end
# it "returns unread, then new, then random" do
# SiteSetting.suggested_topics = 7
# expect(suggested_topics[0]).to eq(partially_read.id)
# expect(suggested_topics[1,3]).to include(new_topic.id)
# expect(suggested_topics[1,3]).to include(closed_topic.id)
# expect(suggested_topics[1,3]).to include(archived_topic.id)
# expect(suggested_topics[4]).to eq(fully_read.id)
# # random doesn't include closed and archived
# end
end end
end end