Skip to content

Commit

Permalink
Fix rails#3737 AS::expand_cache_key generates wrong key in certain si…
Browse files Browse the repository at this point in the history
…tuations (part 2)

`nil` and `false` both expand to `""` (empty string), while `true` expands to
`"true"`; `false` should expand to `"false"`
  • Loading branch information
exviva committed Nov 23, 2011
1 parent d8e6dc9 commit a650dd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions activesupport/test/caching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,33 @@ 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
end
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
end
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
Expand Down

0 comments on commit a650dd0

Please sign in to comment.