Fix for tag test issues

This commit is contained in:
Kyle Drake 2016-05-13 16:42:11 -04:00
parent cef1611003
commit d3c4c5f340
4 changed files with 11 additions and 3 deletions

View file

@ -88,6 +88,7 @@ group :test do
gem 'webmock', require: nil gem 'webmock', require: nil
gem 'stripe-ruby-mock', '2.0.1', require: 'stripe_mock' gem 'stripe-ruby-mock', '2.0.1', require: 'stripe_mock'
gem 'timecop' gem 'timecop'
gem 'mock_redis'
platform :mri, :rbx do platform :mri, :rbx do
gem 'simplecov', require: nil gem 'simplecov', require: nil

View file

@ -101,6 +101,7 @@ GEM
ruby-progressbar ruby-progressbar
mocha (1.1.0) mocha (1.1.0)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mock_redis (0.16.1)
msgpack (0.7.5) msgpack (0.7.5)
multi_json (1.11.2) multi_json (1.11.2)
net-scp (1.2.1) net-scp (1.2.1)
@ -260,6 +261,7 @@ DEPENDENCIES
minitest minitest
minitest-reporters minitest-reporters
mocha mocha
mock_redis
msgpack msgpack
paypal-recurring paypal-recurring
pg pg
@ -301,4 +303,4 @@ DEPENDENCIES
zipruby zipruby
BUNDLED WITH BUNDLED WITH
1.11.2 1.12.1

View file

@ -62,7 +62,12 @@ Sidekiq.configure_client do |config|
config.redis = sidekiq_redis_config config.redis = sidekiq_redis_config
end 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 $redis_cache = Redis::Namespace.new :cache, redis: $redis
# :nocov: # :nocov:

View file

@ -23,7 +23,7 @@ class Tag < Sequel::Model
end end
def self.popular_names(limit=10) def self.popular_names(limit=10)
cache = $redis_cache.get :tag_popular_names cache = $redis_cache['tag_popular_names']
if cache.nil? 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 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 $redis_cache.set :tag_popular_names, res.to_msgpack