1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix dependency tracker bug

This commit is contained in:
Juho Leinonen 2015-02-24 16:08:05 +02:00
parent 5a6868b617
commit 4640c346ea
3 changed files with 20 additions and 5 deletions

View file

@ -1,3 +1,8 @@
* Fixed a dependency tracker bug that caused template dependencies not
count layouts as dependencies for partials.
*Juho Leinonen*
* Extracted `ActionView::Helpers::RecordTagHelper` to external gem * Extracted `ActionView::Helpers::RecordTagHelper` to external gem
(`record_tag_helper`) and added removal notices. (`record_tag_helper`) and added removal notices.

View file

@ -76,6 +76,12 @@ module ActionView
(?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest (?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest
/xm /xm
LAYOUT_DEPENDENCY = /\A
(?:\s*\(?\s*) # optional opening paren surrounded by spaces
(?:.*?#{LAYOUT_HASH_KEY}) # check if the line has layout key declaration
(?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest
/xm
def self.call(name, template) def self.call(name, template)
new(name, template).dependencies new(name, template).dependencies
end end
@ -106,15 +112,20 @@ module ActionView
render_calls = source.split(/\brender\b/).drop(1) render_calls = source.split(/\brender\b/).drop(1)
render_calls.each do |arguments| render_calls.each do |arguments|
arguments.scan(RENDER_ARGUMENTS) do add_dependencies(render_dependencies, arguments, LAYOUT_DEPENDENCY)
add_dynamic_dependency(render_dependencies, Regexp.last_match[:dynamic]) add_dependencies(render_dependencies, arguments, RENDER_ARGUMENTS)
add_static_dependency(render_dependencies, Regexp.last_match[:static])
end
end end
render_dependencies.uniq render_dependencies.uniq
end end
def add_dependencies(render_dependencies, arguments, pattern)
arguments.scan(pattern) do
add_dynamic_dependency(render_dependencies, Regexp.last_match[:dynamic])
add_static_dependency(render_dependencies, Regexp.last_match[:static])
end
end
def add_dynamic_dependency(dependencies, dependency) def add_dynamic_dependency(dependencies, dependency)
if dependency if dependency
dependencies << "#{dependency.pluralize}/#{dependency.singularize}" dependencies << "#{dependency.pluralize}/#{dependency.singularize}"

View file

@ -60,7 +60,6 @@ class ERBTrackerTest < Minitest::Test
end end
def test_dependency_of_template_partial_with_layout def test_dependency_of_template_partial_with_layout
skip # FIXME: Needs to be fixed properly, right now we can only match one dependency per line. Need multiple!
template = FakeTemplate.new("<%# render partial: 'messages/show', layout: 'messages/layout' %>", :erb) template = FakeTemplate.new("<%# render partial: 'messages/show', layout: 'messages/layout' %>", :erb)
tracker = make_tracker("multiple/_dependencies", template) tracker = make_tracker("multiple/_dependencies", template)