correct tests

This commit is contained in:
Sam 2015-02-27 09:40:10 +11:00
parent 68806f40fd
commit ea40dd08e6
2 changed files with 10 additions and 4 deletions

View File

@ -68,6 +68,12 @@ class RandomTopicSelector
results results
end end
def self.clear_cache!
Category.select(:id).each do |c|
$redis.del cache_key(c)
end
end
def self.cache_key(category=nil) def self.cache_key(category=nil)
"random_topic_cache_#{category.try(:id)}" "random_topic_cache_#{category.try(:id)}"
end end

View File

@ -406,7 +406,7 @@ describe TopicQuery do
before do before do
$redis.del RandomTopicSelector.cache_key RandomTopicSelector.clear_cache!
end end
context 'when anonymous' do context 'when anonymous' do
@ -463,12 +463,12 @@ describe TopicQuery do
end 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.stubs(:suggested_topics).returns(1) SiteSetting.suggested_topics = 1
expect(suggested_topics).to eq([partially_read.id]) expect(suggested_topics).to eq([partially_read.id])
end end
it "won't return fully read if there are enough partially read topics and new topics" do it "won't return fully read if there are enough partially read topics and new topics" do
SiteSetting.stubs(:suggested_topics).returns(4) SiteSetting.suggested_topics = 4
expect(suggested_topics[0]).to eq(partially_read.id) 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(new_topic.id)
expect(suggested_topics[1,3]).to include(closed_topic.id) expect(suggested_topics[1,3]).to include(closed_topic.id)
@ -476,7 +476,7 @@ describe TopicQuery do
end end
it "returns unread, then new, then random" do it "returns unread, then new, then random" do
SiteSetting.stubs(:suggested_topics).returns(7) SiteSetting.suggested_topics = 7
expect(suggested_topics[0]).to eq(partially_read.id) 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(new_topic.id)
expect(suggested_topics[1,3]).to include(closed_topic.id) expect(suggested_topics[1,3]).to include(closed_topic.id)