mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #20417 from dubek/fix-template-cache-call-pattern
Improve detection of partial templates eligible for collection caching.
This commit is contained in:
commit
f9996803f8
3 changed files with 36 additions and 1 deletions
|
@ -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).
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue