aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/caching_test.rb
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-02-12 21:52:54 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2016-02-12 22:03:43 +0100
commit48349f28b0b81c5d646ff9670a255f1740d98282 (patch)
treea46442bbd565e354fbc02e8bbe28ceb3a4139f97 /actionpack/test/controller/caching_test.rb
parentdb9ef08a8da60fe28b64bfa0136e7549d526f24d (diff)
downloadrails-48349f28b0b81c5d646ff9670a255f1740d98282.tar.gz
rails-48349f28b0b81c5d646ff9670a255f1740d98282.tar.bz2
rails-48349f28b0b81c5d646ff9670a255f1740d98282.zip
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.
Diffstat (limited to 'actionpack/test/controller/caching_test.rb')
-rw-r--r--actionpack/test/controller/caching_test.rb25
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