Permalink
Browse files

Merge pull request #5394 from erichmenge/master

retrieve_cache_key should work on objects that act like arrays.
  • Loading branch information...
tenderlove committed Mar 12, 2012
2 parents fd22471 + be62367 commit 0f5b32cd0804a3fe26027176db57b8fbd9a52108
Showing with 5 additions and 0 deletions.
  1. +1 −0 activesupport/lib/active_support/cache.rb
  2. +4 −0 activesupport/test/caching_test.rb
@@ -91,6 +91,7 @@ def retrieve_cache_key(key)
case
when key.respond_to?(:cache_key) then key.cache_key
when key.is_a?(Array) then key.map { |element| retrieve_cache_key(element) }.to_param
+ when key.respond_to?(:to_a) then retrieve_cache_key(key.to_a)
else key.to_param
end.to_s
end
@@ -69,6 +69,10 @@ def test_expand_cache_key_of_false
def test_expand_cache_key_of_true
assert_equal 'true', ActiveSupport::Cache.expand_cache_key(true)
end
+
+ def test_expand_cache_key_of_array_like_object
+ assert_equal 'foo/bar/baz', ActiveSupport::Cache.expand_cache_key(%w{foo bar baz}.to_enum)
+ end
end
class CacheStoreSettingTest < ActiveSupport::TestCase

0 comments on commit 0f5b32c

Please sign in to comment.