1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Test collection caching with callable cache key.

When people pass `cache: -> item { item.upcase }` they scope the collection
cache keys so the individual partial cache isn't reused.

Test that behavior.
This commit is contained in:
Kasper Timm Hansen 2016-02-12 21:52:54 +01:00
parent db9ef08a8d
commit 48349f28b0

View file

@ -390,6 +390,11 @@ class CollectionCacheController < ActionController::Base
@customers = [Customer.new('david', 1)]
render partial: 'customers/commented_customer', collection: @customers, as: :customer
end
def index_with_callable_cache_key
@customers = [Customer.new('david', 1)]
render @customers, cache: -> customer { 'cached_david' }
end
end
class AutomaticCollectionCacheTest < ActionController::TestCase
@ -430,6 +435,26 @@ class AutomaticCollectionCacheTest < ActionController::TestCase
get :index_with_comment
assert_equal 1, @controller.partial_rendered_times
end
def test_caching_with_callable_cache_key
get :index_with_callable_cache_key
assert_equal 1, @controller.partial_rendered_times
assert_select ':root', 'david, 1'
get :index_with_callable_cache_key
assert_equal 1, @controller.partial_rendered_times
assert_select ':root', 'david, 1'
end
def test_caching_mixing_callable_cache_key_and_automatic_caching
get :index
assert_equal 1, @controller.partial_rendered_times
assert_select ':root', 'david, 1'
get :index_with_callable_cache_key
assert_equal 1, @controller.partial_rendered_times, 'individual cache not reused with collection'
assert_select ':root', 'david, 1'
end
end
class FragmentCacheKeyTestController < CachingController