aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorOlek Janiszewski <olek.janiszewski@gmail.com>2011-11-23 18:11:36 +0100
committerOlek Janiszewski <olek.janiszewski@gmail.com>2011-11-23 18:11:38 +0100
commita650dd05f82028e8d1310f1b68b7bc430ea47dcf (patch)
tree9bd9b1a6ea04610dea87b357bb8ee4f19557f8bb /activesupport
parentd8e6dc9cf12096908a7a53dec07a397ba23b1088 (diff)
downloadrails-a650dd05f82028e8d1310f1b68b7bc430ea47dcf.tar.gz
rails-a650dd05f82028e8d1310f1b68b7bc430ea47dcf.tar.bz2
rails-a650dd05f82028e8d1310f1b68b7bc430ea47dcf.zip
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"`
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/cache.rb2
-rw-r--r--activesupport/test/caching_test.rb15
2 files changed, 14 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index cfd1a6dbe3..12eeff4f4b 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -84,7 +84,7 @@ module ActiveSupport
case
when key.respond_to?(:cache_key) then key.cache_key
when key.is_a?(Array) then key.map { |element| expand_cache_key(element) }.to_param
- when key then key.to_param
+ else key.to_param
end.to_s
expanded_cache_key
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