Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #3737 AS::expand_cache_key generates wrong key in certain situati…

…ons (part 2)

`nil` and `false` both expand to `""` (empty string), while `true` expands to
`"true"`; `false` should expand to `"false"`
  • Loading branch information...
commit a650dd05f82028e8d1310f1b68b7bc430ea47dcf 1 parent d8e6dc9
Olek Janiszewski exviva authored
2  activesupport/lib/active_support/cache.rb
View
@@ -84,7 +84,7 @@ def self.expand_cache_key(key, namespace = nil)
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
15 activesupport/test/caching_test.rb
View
@@ -42,7 +42,7 @@ def test_expand_cache_key_rails_cache_id_should_win_over_rails_app_version
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 @@ def key.cache_key
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 @@ def key.cache_key
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
Please sign in to comment.
Something went wrong with that request. Please try again.