From d8e6dc9cf12096908a7a53dec07a397ba23b1088 Mon Sep 17 00:00:00 2001 From: Olek Janiszewski Date: Wed, 23 Nov 2011 18:06:15 +0100 Subject: Fix #3737 AS::expand_cache_key generates wrong key in certain situations `cache_key` method is never called when the argument is a 1-element array with something that responds to `cache_key` --- activesupport/test/caching_test.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'activesupport/test/caching_test.rb') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index b1b6de0613..5c844b8122 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -12,10 +12,10 @@ class CacheKeyTest < ActiveSupport::TestCase 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/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo]) assert_equal 'c99/c99/foo/c99/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/c99/foo', ActiveSupport::Cache.expand_cache_key([:foo], :nm) assert_equal 'nm/c99/c99/foo/c99/bar', ActiveSupport::Cache.expand_cache_key([:foo, :bar], :nm) ensure ENV['RAILS_CACHE_ID'] = nil @@ -50,6 +50,14 @@ class CacheKeyTest < ActiveSupport::TestCase assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key(key) end + def test_array_with_something_that_responds_to_cache_key + key = 'foo' + def key.cache_key + :foo_key + end + assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key([key]) + end + end class CacheStoreSettingTest < ActiveSupport::TestCase -- cgit v1.2.3 From a650dd05f82028e8d1310f1b68b7bc430ea47dcf Mon Sep 17 00:00:00 2001 From: Olek Janiszewski Date: Wed, 23 Nov 2011 18:11:36 +0100 Subject: Fix #3737 AS::expand_cache_key generates wrong key in certain situations (part 2) `nil` and `false` both expand to `""` (empty string), while `true` expands to `"true"`; `false` should expand to `"false"` --- activesupport/test/caching_test.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'activesupport/test/caching_test.rb') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 5c844b8122..8871b1b0e9 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -42,7 +42,7 @@ class CacheKeyTest < ActiveSupport::TestCase end end - def test_respond_to_cache_key + def test_expand_cache_key_respond_to_cache_key key = 'foo' def key.cache_key :foo_key @@ -50,7 +50,7 @@ class CacheKeyTest < ActiveSupport::TestCase assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key(key) end - def test_array_with_something_that_responds_to_cache_key + def test_expand_cache_key_array_with_something_that_responds_to_cache_key key = 'foo' def key.cache_key :foo_key @@ -58,6 +58,17 @@ class CacheKeyTest < ActiveSupport::TestCase assert_equal 'foo_key', ActiveSupport::Cache.expand_cache_key([key]) end + def test_expand_cache_key_of_nil + assert_equal '', ActiveSupport::Cache.expand_cache_key(nil) + end + + def test_expand_cache_key_of_false + assert_equal 'false', ActiveSupport::Cache.expand_cache_key(false) + end + + def test_expand_cache_key_of_true + assert_equal 'true', ActiveSupport::Cache.expand_cache_key(true) + end end class CacheStoreSettingTest < ActiveSupport::TestCase -- cgit v1.2.3