diff options
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 74c78dfa8e..a1785d9ab1 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -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 |