1
0
Fork 0
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:
Adam Richardson 2018-03-12 19:52:26 -04:00 committed by Jeremy Daer
parent 4483c926fc
commit a061ae91a9
No known key found for this signature in database
GPG key ID: AB8F6399D5C60664
2 changed files with 7 additions and 1 deletions

View file

@ -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

View file

@ -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|