From ea40dd08e633c87b0aadf4b95fb8911be1584b97 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 27 Feb 2015 09:40:10 +1100 Subject: [PATCH] correct tests --- app/services/random_topic_selector.rb | 6 ++++++ spec/components/topic_query_spec.rb | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/services/random_topic_selector.rb b/app/services/random_topic_selector.rb index ac4945afe..8ce962f76 100644 --- a/app/services/random_topic_selector.rb +++ b/app/services/random_topic_selector.rb @@ -68,6 +68,12 @@ class RandomTopicSelector results end + def self.clear_cache! + Category.select(:id).each do |c| + $redis.del cache_key(c) + end + end + def self.cache_key(category=nil) "random_topic_cache_#{category.try(:id)}" end diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index c4223114e..a1f9bd3ad 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -406,7 +406,7 @@ describe TopicQuery do before do - $redis.del RandomTopicSelector.cache_key + RandomTopicSelector.clear_cache! end context 'when anonymous' do @@ -463,12 +463,12 @@ describe TopicQuery do end 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]) end 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[1,3]).to include(new_topic.id) expect(suggested_topics[1,3]).to include(closed_topic.id) @@ -476,7 +476,7 @@ describe TopicQuery do end 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[1,3]).to include(new_topic.id) expect(suggested_topics[1,3]).to include(closed_topic.id)