aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-01-21 23:59:38 -0500
committerGeorge Claghorn <george@basecamp.com>2018-01-21 23:59:38 -0500
commitebc28aa74af410c590534140cc4e4bd0b69a045a (patch)
tree67b5259e7c4621cf1aeb61129b6a06e2253561a5 /activesupport/test
parent5e02f3b9ff74b0efda38a217bd789a6f9d621aea (diff)
downloadrails-ebc28aa74af410c590534140cc4e4bd0b69a045a.tar.gz
rails-ebc28aa74af410c590534140cc4e4bd0b69a045a.tar.bz2
rails-ebc28aa74af410c590534140cc4e4bd0b69a045a.zip
Pass desired driver to Redis client constructor rather than munging global config
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/cache/stores/redis_cache_store_test.rb28
1 files changed, 12 insertions, 16 deletions
diff --git a/activesupport/test/cache/stores/redis_cache_store_test.rb b/activesupport/test/cache/stores/redis_cache_store_test.rb
index ee79f954ec..3635703002 100644
--- a/activesupport/test/cache/stores/redis_cache_store_test.rb
+++ b/activesupport/test/cache/stores/redis_cache_store_test.rb
@@ -5,13 +5,9 @@ require "active_support/cache"
require "active_support/cache/redis_cache_store"
require_relative "../behaviors"
-driver_name = %w[ ruby hiredis ].include?(ENV["REDIS_DRIVER"]) ? ENV["REDIS_DRIVER"] : "hiredis"
-driver = Object.const_get("Redis::Connection::#{driver_name.camelize}")
-
-Redis::Connection.drivers.clear
-Redis::Connection.drivers.append(driver)
-
module ActiveSupport::Cache::RedisCacheStoreTests
+ DRIVER = %w[ ruby hiredis ].include?(ENV["REDIS_DRIVER"]) ? ENV["REDIS_DRIVER"] : "hiredis"
+
class LookupTest < ActiveSupport::TestCase
test "may be looked up as :redis_cache_store" do
assert_kind_of ActiveSupport::Cache::RedisCacheStore,
@@ -24,7 +20,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
assert_called_with Redis, :new, [
url: nil,
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
- reconnect_attempts: 0,
+ reconnect_attempts: 0, driver: DRIVER
] do
build
end
@@ -34,7 +30,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
assert_called_with Redis, :new, [
url: nil,
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
- reconnect_attempts: 0,
+ reconnect_attempts: 0, driver: DRIVER
] do
build url: []
end
@@ -44,7 +40,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
assert_called_with Redis, :new, [
url: "redis://localhost:6379/0",
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
- reconnect_attempts: 0,
+ reconnect_attempts: 0, driver: DRIVER
] do
build url: "redis://localhost:6379/0"
end
@@ -54,7 +50,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
assert_called_with Redis, :new, [
url: "redis://localhost:6379/0",
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
- reconnect_attempts: 0,
+ reconnect_attempts: 0, driver: DRIVER
] do
build url: %w[ redis://localhost:6379/0 ]
end
@@ -64,10 +60,10 @@ module ActiveSupport::Cache::RedisCacheStoreTests
assert_called_with Redis, :new, [
[ url: "redis://localhost:6379/0",
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
- reconnect_attempts: 0 ],
+ reconnect_attempts: 0, driver: DRIVER ],
[ url: "redis://localhost:6379/1",
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
- reconnect_attempts: 0 ],
+ reconnect_attempts: 0, driver: DRIVER ],
], returns: Redis.new do
@cache = build url: %w[ redis://localhost:6379/0 redis://localhost:6379/1 ]
assert_kind_of ::Redis::Distributed, @cache.redis
@@ -83,7 +79,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
private
def build(**kwargs)
- ActiveSupport::Cache::RedisCacheStore.new(**kwargs).tap do |cache|
+ ActiveSupport::Cache::RedisCacheStore.new(driver: DRIVER, **kwargs).tap do |cache|
cache.redis
end
end
@@ -93,11 +89,11 @@ module ActiveSupport::Cache::RedisCacheStoreTests
setup do
@namespace = "namespace"
- @cache = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace, expires_in: 60)
+ @cache = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace, expires_in: 60, driver: DRIVER)
# @cache.logger = Logger.new($stdout) # For test debugging
# For LocalCacheBehavior tests
- @peek = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace)
+ @peek = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, namespace: @namespace, driver: DRIVER)
end
teardown do
@@ -120,7 +116,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
include EncodedKeyCacheBehavior
setup do
- @cache = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1)
+ @cache = ActiveSupport::Cache::RedisCacheStore.new(timeout: 0.1, driver: DRIVER)
@cache.logger = nil
end
end