Merge pull request #4552 from tgxworld/extract_test_logic

Ensure we don't run `$redis.keys` in production.
This commit is contained in:
Guo Xiang Tan 2016-11-16 10:05:02 +08:00 committed by GitHub
commit b5dc68cd52
2 changed files with 7 additions and 8 deletions

View File

@ -77,10 +77,6 @@ class RandomTopicSelector
results
end
def self.clear_cache!
$redis.keys('random_topic_cache*').each{|k| $redis.del k}
end
def self.cache_key(category=nil)
"random_topic_cache_#{category.try(:id)}"
end

View File

@ -642,9 +642,12 @@ describe TopicQuery do
end
context 'suggested_for' do
def clear_cache!
$redis.keys('random_topic_cache*').each{|k| $redis.del k}
end
before do
RandomTopicSelector.clear_cache!
clear_cache!
end
context 'when anonymous' do
@ -674,7 +677,7 @@ describe TopicQuery do
let(:suggested_topics) {
tt = topic
# lets clear cache once category is created - working around caching is hard
RandomTopicSelector.clear_cache!
clear_cache!
topic_query.list_suggested_for(tt).topics.map{|t| t.id}
}
@ -691,11 +694,11 @@ describe TopicQuery do
SiteSetting.suggested_topics_max_days_old = 1365
tt = topic
RandomTopicSelector.clear_cache!
clear_cache!
expect(topic_query.list_suggested_for(tt).topics.length).to eq(2)
SiteSetting.suggested_topics_max_days_old = 365
RandomTopicSelector.clear_cache!
clear_cache!
expect(topic_query.list_suggested_for(tt).topics.length).to eq(1)
end