aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test
diff options
context:
space:
mode:
authorDov Murik <dov.murik@gmail.com>2015-07-04 22:34:00 -0400
committerDov Murik <dov.murik@gmail.com>2015-07-07 16:57:09 -0400
commit5a41d00455f67a03e3cb77cd89c3b710a7c389d0 (patch)
tree04581f1a19441de919eacfd5ce3a4b0481c03658 /actionview/test
parent062cbd18ddbf6ef48c9a9a2a69081737aebbee89 (diff)
downloadrails-5a41d00455f67a03e3cb77cd89c3b710a7c389d0.tar.gz
rails-5a41d00455f67a03e3cb77cd89c3b710a7c389d0.tar.bz2
rails-5a41d00455f67a03e3cb77cd89c3b710a7c389d0.zip
Support explicit defintion of resouce name for collection caching.
If a template includes `# Template Collection: ...` anywhere in its source, that name will be used as the cache name for the partial that is rendered for the collection. This allows users to enable collection caching even if the template doesn't start with `<% cache ... do %>`. Moreover, the `# Template Collection: ...` notation is recognized in all template types (and template types other than ERB can define a resource_cache_call_pattern method to allow the `cache ... do` pattern to be recognized too).
Diffstat (limited to 'actionview/test')
-rw-r--r--actionview/test/template/template_test.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/actionview/test/template/template_test.rb b/actionview/test/template/template_test.rb
index d17034e88f..d3b51cd629 100644
--- a/actionview/test/template/template_test.rb
+++ b/actionview/test/template/template_test.rb
@@ -194,14 +194,15 @@ class TestERBTemplate < ActiveSupport::TestCase
[
"<%= 'Hello' %>",
"<% cache_customer = 42 %>",
- "<% cache customer.name do %><% end %>"
+ "<% cache customer.name do %><% end %>",
+ "<% my_cache customer do %><% end %>"
].each do |body|
template = new_template(body, virtual_path: "test/foo/_customer")
assert_not template.eligible_for_collection_caching?, "Template #{body.inspect} should not be eligible for collection caching"
end
end
- def test_eligible_for_collection_caching_with_cache_call
+ def test_eligible_for_collection_caching_with_cache_call_or_explicit
[
"<% cache customer do %><% end %>",
"<% cache(customer) do %><% end %>",
@@ -213,7 +214,8 @@ class TestERBTemplate < ActiveSupport::TestCase
"<%# comment %><% cache customer do %><% end %>",
"<%# comment %>\n<% cache customer do %><% end %>",
"<%# comment\n line 2\n line 3 %>\n<% cache customer do %><% end %>",
- "<%# comment 1 %>\n<%# comment 2 %>\n<% cache customer do %><% end %>"
+ "<%# comment 1 %>\n<%# comment 2 %>\n<% cache customer do %><% end %>",
+ "<%# comment 1 %>\n<%# Template Collection: customer %>\n<% my_cache customer do %><% end %>"
].each do |body|
template = new_template(body, virtual_path: "test/foo/_customer")
assert template.eligible_for_collection_caching?, "Template #{body.inspect} should be eligible for collection caching"