diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-16 14:40:09 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-16 14:40:09 -0800 |
commit | 4f35d5a18b1192f03c36b23b2f6a8b3b2d2c0347 (patch) | |
tree | 804acfdb76d559aac44a31ea158abc2f3ee844d9 | |
parent | 0065f378262dc3f47880ce6211c7474bc7d11f0b (diff) | |
parent | abe915f23777efe10f17d611bf5718ca855a0704 (diff) | |
download | rails-4f35d5a18b1192f03c36b23b2f6a8b3b2d2c0347.tar.gz rails-4f35d5a18b1192f03c36b23b2f6a8b3b2d2c0347.tar.bz2 rails-4f35d5a18b1192f03c36b23b2f6a8b3b2d2c0347.zip |
Merge pull request #4007 from exviva/expand_cache_key_for_one_element_array
Fix expanding cache key for single element arrays
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 2 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 22 |
2 files changed, 16 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 9711ed6f73..7d032ca984 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -91,7 +91,7 @@ module ActiveSupport 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.is_a?(Array) then ['Array', *key.map { |element| retrieve_cache_key(element) }].to_param else key.to_param end.to_s end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index ab29ddecc5..5488070d8c 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -4,19 +4,19 @@ require 'active_support/cache' class CacheKeyTest < ActiveSupport::TestCase def test_expand_cache_key - assert_equal '1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true]) - assert_equal 'name/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true], :name) + assert_equal 'Array/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true]) + assert_equal 'name/Array/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true], :name) end def test_expand_cache_key_with_rails_cache_id begin ENV['RAILS_CACHE_ID'] = 'c99' assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key(:foo) - assert_equal 'c99/foo', ActiveSupport::Cache.expand_cache_key([:foo]) - assert_equal 'c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar]) + assert_equal 'c99/Array/foo', ActiveSupport::Cache.expand_cache_key([:foo]) + assert_equal 'c99/Array/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar]) assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key(:foo, :nm) - assert_equal 'nm/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) - assert_equal 'nm/c99/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) + assert_equal 'nm/c99/Array/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) + assert_equal 'nm/c99/Array/foo/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) ensure ENV['RAILS_CACHE_ID'] = nil end @@ -55,7 +55,7 @@ class CacheKeyTest < ActiveSupport::TestCase def key.cache_key :foo_key end - assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key([key]) + assert_equal 'Array/foo_key', ActiveSupport::Cache.expand_cache_key([key]) end def test_expand_cache_key_of_nil @@ -69,6 +69,14 @@ class CacheKeyTest < ActiveSupport::TestCase def test_expand_cache_key_of_true assert_equal 'true', ActiveSupport::Cache.expand_cache_key(true) end + + def test_expand_cache_key_of_one_element_array_different_than_key_of_element + element = 'foo' + array = [element] + element_cache_key = ActiveSupport::Cache.expand_cache_key(element) + array_cache_key = ActiveSupport::Cache.expand_cache_key(array) + assert_not_equal element_cache_key, array_cache_key + end end class CacheStoreSettingTest < ActiveSupport::TestCase |