mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
4483c926fc
commit
a061ae91a9
2 changed files with 7 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue