diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-06-26 23:01:07 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-06-26 23:01:07 +0200 |
commit | f9996803f857afcd6f32e18e63ab0269ac8213e6 (patch) | |
tree | c2606dbeec96ea2092c6f5849775f2ae8fa6da90 | |
parent | 4b4075be11753b49b240adbbefead712e83ca1a7 (diff) | |
parent | d51e2eefd5c50cef366ddc96a3b93af0395755f1 (diff) | |
download | rails-f9996803f857afcd6f32e18e63ab0269ac8213e6.tar.gz rails-f9996803f857afcd6f32e18e63ab0269ac8213e6.tar.bz2 rails-f9996803f857afcd6f32e18e63ab0269ac8213e6.zip |
Merge pull request #20417 from dubek/fix-template-cache-call-pattern
Improve detection of partial templates eligible for collection caching.
-rw-r--r-- | actionview/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actionview/lib/action_view/template/handlers/erb.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/template_test.rb | 30 |
3 files changed, 36 insertions, 1 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 7b6008d5ed..fe47fb47fd 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,8 @@ +* Improve detection of partial templates eligible for collection caching, + now allowing multi-line comments at the beginning of the template file. + + *Dov Murik* + * Raise an ArgumentError when a false value for `include_blank` is passed to a required select field (to comply with the HTML5 spec). diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb index 88a8570706..da96347e4d 100644 --- a/actionview/lib/action_view/template/handlers/erb.rb +++ b/actionview/lib/action_view/template/handlers/erb.rb @@ -138,7 +138,7 @@ module ActionView # # <% cache notification.event do %> # => nil def resource_cache_call_pattern - /\A(?:<%#.*%>\n?)?<% cache\(?\s*(\w+\.?)/ + /\A(?:<%#.*%>)*\s*<%\s*cache\(?\s*(\w+)[\s\)]/m end private diff --git a/actionview/test/template/template_test.rb b/actionview/test/template/template_test.rb index aae6a9aa09..d17034e88f 100644 --- a/actionview/test/template/template_test.rb +++ b/actionview/test/template/template_test.rb @@ -190,6 +190,36 @@ class TestERBTemplate < ActiveSupport::TestCase assert_match(/\xFC/, e.message) end + def test_not_eligible_for_collection_caching_without_cache_call + [ + "<%= 'Hello' %>", + "<% cache_customer = 42 %>", + "<% cache customer.name 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 + [ + "<% cache customer do %><% end %>", + "<% cache(customer) do %><% end %>", + "<% cache( customer) do %><% end %>", + "<% cache( customer ) do %><% end %>", + "<%cache customer do %><% end %>", + "<% cache customer do %><% end %>", + " <% cache customer do %>\n<% end %>\n", + "<%# 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 %>" + ].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" + end + end + def with_external_encoding(encoding) old = Encoding.default_external Encoding::Converter.new old, encoding if old != encoding |