diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2013-02-25 05:11:56 -0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2013-02-25 05:11:56 -0800 |
commit | 2b7b5f535cac4b2e17955e23d05604388ef72c04 (patch) | |
tree | 9714b12cfac04056c8711d42a5c96256e5bde908 /actionpack/test | |
parent | add8b518c50d5c6378b1230f78ea443d8da0edb1 (diff) | |
parent | ec23296eb607d7974c7281d520b543640024418f (diff) | |
download | rails-2b7b5f535cac4b2e17955e23d05604388ef72c04.tar.gz rails-2b7b5f535cac4b2e17955e23d05604388ef72c04.tar.bz2 rails-2b7b5f535cac4b2e17955e23d05604388ef72c04.zip |
Merge pull request #8530 from dasch/dependency-trackers
Custom dependency trackers for the template digestor
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/dependency_tracker_test.rb | 46 | ||||
-rw-r--r-- | actionpack/test/template/digestor_test.rb | 3 |
2 files changed, 48 insertions, 1 deletions
diff --git a/actionpack/test/template/dependency_tracker_test.rb b/actionpack/test/template/dependency_tracker_test.rb new file mode 100644 index 0000000000..9c68afbdbd --- /dev/null +++ b/actionpack/test/template/dependency_tracker_test.rb @@ -0,0 +1,46 @@ +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 + end + + class FakeTemplate + attr_reader :source, :handler + + def initialize(source, handler = Neckbeard) + @source, @handler = source, handler + end + end + + def tracker + ActionView::DependencyTracker + end + + def setup + ActionView::Template.register_template_handler :neckbeard, Neckbeard + tracker.register_tracker(:neckbeard, NeckbeardTracker) + end + + def teardown + tracker.remove_tracker(:neckbeard) + 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 + + 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 +end diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 849e2981a6..e29cecabc0 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -2,10 +2,11 @@ require 'abstract_unit' require 'fileutils' class FixtureTemplate - attr_reader :source + attr_reader :source, :handler def initialize(template_path) @source = File.read(template_path) + @handler = ActionView::Template.handler_for_extension(:erb) rescue Errno::ENOENT raise ActionView::MissingTemplate.new([], "", [], true, []) end |