diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2013-06-04 12:45:15 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2013-06-04 12:45:15 -0700 |
commit | 95296f1a7a2ae0490546c0d3010fc435558911c8 (patch) | |
tree | 5d8de3cec11e9cf69824fd06c02030fe6dfb87d3 /actionpack | |
parent | bc8f8026232bdc55ebed24d8326a863036b816fd (diff) | |
parent | 2a576dd257647871660c3e86f0c4fcddbb5b7105 (diff) | |
download | rails-95296f1a7a2ae0490546c0d3010fc435558911c8.tar.gz rails-95296f1a7a2ae0490546c0d3010fc435558911c8.tar.bz2 rails-95296f1a7a2ae0490546c0d3010fc435558911c8.zip |
Merge pull request #10841 from latortuga/fix-underscore-dependency-tracking
Fix mismatching variable names when using an underscore
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/dependency_tracker.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/dependency_tracker_test.rb | 54 |
2 files changed, 42 insertions, 14 deletions
diff --git a/actionpack/lib/action_view/dependency_tracker.rb b/actionpack/lib/action_view/dependency_tracker.rb index 45d17be605..b2e8334077 100644 --- a/actionpack/lib/action_view/dependency_tracker.rb +++ b/actionpack/lib/action_view/dependency_tracker.rb @@ -74,7 +74,7 @@ module ActionView # render(@topic) => render("topics/topic") # render(topics) => render("topics/topic") # render(message.topics) => render("topics/topic") - collect { |name| name.sub(/\A@?([a-z]+\.)*([a-z_]+)\z/) { "#{$2.pluralize}/#{$2.singularize}" } }. + collect { |name| name.sub(/\A@?([a-z_]+\.)*([a-z_]+)\z/) { "#{$2.pluralize}/#{$2.singularize}" } }. # render("headline") => render("message/headline") collect { |name| name.include?("/") ? name : "#{directory}/#{name}" }. diff --git a/actionpack/test/template/dependency_tracker_test.rb b/actionpack/test/template/dependency_tracker_test.rb index 9c68afbdbd..8588925de3 100644 --- a/actionpack/test/template/dependency_tracker_test.rb +++ b/actionpack/test/template/dependency_tracker_test.rb @@ -1,24 +1,24 @@ require 'abstract_unit' require 'action_view/dependency_tracker' -class DependencyTrackerTest < ActionView::TestCase - Neckbeard = lambda {|template| template.source } - Bowtie = lambda {|template| template.source } - - class NeckbeardTracker - def self.call(name, template) - ["foo/#{name}"] - end +class NeckbeardTracker + def self.call(name, template) + ["foo/#{name}"] end +end - class FakeTemplate - attr_reader :source, :handler +class FakeTemplate + attr_reader :source, :handler - def initialize(source, handler = Neckbeard) - @source, @handler = source, handler - end + def initialize(source, handler = Neckbeard) + @source, @handler = source, handler end +end + +Neckbeard = lambda {|template| template.source } +Bowtie = lambda {|template| template.source } +class DependencyTrackerTest < ActionView::TestCase def tracker ActionView::DependencyTracker end @@ -44,3 +44,31 @@ class DependencyTrackerTest < ActionView::TestCase assert_equal [], dependencies end end + +class ERBTrackerTest < MiniTest::Unit::TestCase + def make_tracker(name, template) + ActionView::DependencyTracker::ERBTracker.new(name, template) + end + + def test_dependency_of_erb_template_with_number_in_filename + template = FakeTemplate.new("<%# render 'messages/message123' %>", :erb) + tracker = make_tracker('messages/_message123', template) + + assert_equal ["messages/message123"], tracker.dependencies + end + + def test_finds_dependency_in_correct_directory + template = FakeTemplate.new("<%# render(message.topic) %>", :erb) + tracker = make_tracker('messages/_message', template) + + assert_equal ["topics/topic"], tracker.dependencies + end + + def test_finds_dependency_in_correct_directory_with_underscore + template = FakeTemplate.new("<%# render(message_type.messages) %>", :erb) + tracker = make_tracker('message_types/_message_type', template) + + assert_equal ["messages/message"], tracker.dependencies + end +end + |