From d3c4c5f3404a414fdb18a75569cf31bc494c40b0 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Fri, 13 May 2016 16:42:11 -0400 Subject: [PATCH] Fix for tag test issues --- Gemfile | 1 + Gemfile.lock | 4 +++- environment.rb | 7 ++++++- models/tag.rb | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 0f11c869..fe74a68d 100644 --- a/Gemfile +++ b/Gemfile @@ -88,6 +88,7 @@ group :test do gem 'webmock', require: nil gem 'stripe-ruby-mock', '2.0.1', require: 'stripe_mock' gem 'timecop' + gem 'mock_redis' platform :mri, :rbx do gem 'simplecov', require: nil diff --git a/Gemfile.lock b/Gemfile.lock index c6597bfb..83cef5e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,6 +101,7 @@ GEM ruby-progressbar mocha (1.1.0) metaclass (~> 0.0.1) + mock_redis (0.16.1) msgpack (0.7.5) multi_json (1.11.2) net-scp (1.2.1) @@ -260,6 +261,7 @@ DEPENDENCIES minitest minitest-reporters mocha + mock_redis msgpack paypal-recurring pg @@ -301,4 +303,4 @@ DEPENDENCIES zipruby BUNDLED WITH - 1.11.2 + 1.12.1 diff --git a/environment.rb b/environment.rb index 6a3baa04..387685a6 100644 --- a/environment.rb +++ b/environment.rb @@ -62,7 +62,12 @@ Sidekiq.configure_client do |config| config.redis = sidekiq_redis_config end -$redis = Redis.new +if ENV['RACK_ENV'] == 'test' + $redis = MockRedis.new +else + $redis = Redis.new +end + $redis_cache = Redis::Namespace.new :cache, redis: $redis # :nocov: diff --git a/models/tag.rb b/models/tag.rb index e5c7bdb0..e1844e28 100644 --- a/models/tag.rb +++ b/models/tag.rb @@ -23,7 +23,7 @@ class Tag < Sequel::Model end def self.popular_names(limit=10) - cache = $redis_cache.get :tag_popular_names + cache = $redis_cache['tag_popular_names'] if cache.nil? res = DB["select tags.name,count(*) as c from sites_tags inner join tags on tags.id=sites_tags.tag_id where tags.name != '' and tags.is_nsfw='f' group by tags.name having count(*) > 1 order by c desc LIMIT ?", limit].all $redis_cache.set :tag_popular_names, res.to_msgpack