2012-12-16 17:38:46 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'action_view/dependency_tracker'
|
|
|
|
|
2013-06-04 15:39:50 -04:00
|
|
|
class NeckbeardTracker
|
|
|
|
def self.call(name, template)
|
|
|
|
["foo/#{name}"]
|
2012-12-16 17:38:46 -05:00
|
|
|
end
|
2013-06-04 15:39:50 -04:00
|
|
|
end
|
2012-12-16 17:38:46 -05:00
|
|
|
|
2013-06-04 15:39:50 -04:00
|
|
|
class FakeTemplate
|
|
|
|
attr_reader :source, :handler
|
2012-12-16 17:38:46 -05:00
|
|
|
|
2013-06-04 15:39:50 -04:00
|
|
|
def initialize(source, handler = Neckbeard)
|
|
|
|
@source, @handler = source, handler
|
2012-12-16 17:38:46 -05:00
|
|
|
end
|
2013-06-04 15:39:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Neckbeard = lambda {|template| template.source }
|
|
|
|
Bowtie = lambda {|template| template.source }
|
2012-12-16 17:38:46 -05:00
|
|
|
|
2013-06-04 15:39:50 -04:00
|
|
|
class DependencyTrackerTest < ActionView::TestCase
|
2012-12-16 17:38:46 -05:00
|
|
|
def tracker
|
|
|
|
ActionView::DependencyTracker
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
2013-02-20 10:42:30 -05:00
|
|
|
ActionView::Template.register_template_handler :neckbeard, Neckbeard
|
|
|
|
tracker.register_tracker(:neckbeard, NeckbeardTracker)
|
2012-12-16 17:38:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2013-02-20 10:42:30 -05:00
|
|
|
tracker.remove_tracker(:neckbeard)
|
2012-12-16 17:38:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_finds_tracker_by_template_handler
|
|
|
|
template = FakeTemplate.new("boo/hoo")
|
|
|
|
dependencies = tracker.find_dependencies("boo/hoo", template)
|
|
|
|
assert_equal ["foo/boo/hoo"], dependencies
|
|
|
|
end
|
2012-12-17 15:26:55 -05:00
|
|
|
|
|
|
|
def test_returns_empty_array_if_no_tracker_is_found
|
|
|
|
template = FakeTemplate.new("boo/hoo", Bowtie)
|
|
|
|
dependencies = tracker.find_dependencies("boo/hoo", template)
|
|
|
|
assert_equal [], dependencies
|
|
|
|
end
|
2012-12-16 17:38:46 -05:00
|
|
|
end
|
2013-06-04 15:39:50 -04:00
|
|
|
|
2013-06-12 07:20:43 -04:00
|
|
|
class ERBTrackerTest < Minitest::Test
|
2013-06-04 15:39:50 -04:00
|
|
|
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
|
|
|
|
|