diff options
author | Adam Richardson <adam.richardson@coinbase.com> | 2018-03-12 19:52:26 -0400 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2018-03-12 18:43:03 -0700 |
commit | a061ae91a90a1fbd909f647dcd219af197bd30a9 (patch) | |
tree | b9deadcffc15871de59c0a2faf520575bca6ec23 | |
parent | 4483c926fce008c47179fda1b380d61f359c811f (diff) | |
download | rails-a061ae91a90a1fbd909f647dcd219af197bd30a9.tar.gz rails-a061ae91a90a1fbd909f647dcd219af197bd30a9.tar.bz2 rails-a061ae91a90a1fbd909f647dcd219af197bd30a9.zip |
Redis cache store: fix constructing with a Redis instance
Since `Redis#call` duck types as a Proc, we'd call `#call` on it,
thinking it's a Proc. Fixed by check for the Proc explicitly instead of
duck typing on `#call`.
References #32233
-rw-r--r-- | activesupport/lib/active_support/cache/redis_cache_store.rb | 2 | ||||
-rw-r--r-- | activesupport/test/cache/stores/redis_cache_store_test.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/cache/redis_cache_store.rb b/activesupport/lib/active_support/cache/redis_cache_store.rb index 64bc77cf22..a134bb7095 100644 --- a/activesupport/lib/active_support/cache/redis_cache_store.rb +++ b/activesupport/lib/active_support/cache/redis_cache_store.rb @@ -118,7 +118,7 @@ module ActiveSupport def build_redis(redis: nil, url: nil, **redis_options) #:nodoc: urls = Array(url) - if redis.respond_to?(:call) + if redis.is_a?(Proc) redis.call elsif redis redis diff --git a/activesupport/test/cache/stores/redis_cache_store_test.rb b/activesupport/test/cache/stores/redis_cache_store_test.rb index 375993a632..dda96b68fb 100644 --- a/activesupport/test/cache/stores/redis_cache_store_test.rb +++ b/activesupport/test/cache/stores/redis_cache_store_test.rb @@ -95,6 +95,12 @@ module ActiveSupport::Cache::RedisCacheStoreTests end end + test "instance of Redis uses given instance" do + redis_instance = Redis.new + @cache = build(redis: redis_instance) + assert_same @cache.redis, redis_instance + end + private def build(**kwargs) ActiveSupport::Cache::RedisCacheStore.new(driver: DRIVER, **kwargs).tap do |cache| |