diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/dependency_tracker.rb | 9 | ||||
-rw-r--r-- | actionpack/test/template/dependency_tracker_test.rb | 11 |
2 files changed, 16 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/dependency_tracker.rb b/actionpack/lib/action_view/dependency_tracker.rb index 3478e34fe3..b817b9bdd7 100644 --- a/actionpack/lib/action_view/dependency_tracker.rb +++ b/actionpack/lib/action_view/dependency_tracker.rb @@ -5,8 +5,13 @@ module ActionView @trackers = ThreadSafe::Cache.new def self.find_dependencies(name, template) - handler = template.handler - @trackers.fetch(handler).call(name, template) + tracker = @trackers[template.handler] + + if tracker.present? + tracker.call(name, template) + else + [] + end end def self.register_tracker(handler, tracker) diff --git a/actionpack/test/template/dependency_tracker_test.rb b/actionpack/test/template/dependency_tracker_test.rb index 5b2ec0eb2d..714e2d6b29 100644 --- a/actionpack/test/template/dependency_tracker_test.rb +++ b/actionpack/test/template/dependency_tracker_test.rb @@ -3,6 +3,7 @@ require 'action_view/dependency_tracker' class DependencyTrackerTest < ActionView::TestCase Neckbeard = Class.new + Bowtie = Class.new class NeckbeardTracker def self.call(name, template) @@ -13,8 +14,8 @@ class DependencyTrackerTest < ActionView::TestCase class FakeTemplate attr_reader :source, :handler - def initialize(source) - @source, @handler = source, Neckbeard + def initialize(source, handler = Neckbeard) + @source, @handler = source, handler end end @@ -35,4 +36,10 @@ class DependencyTrackerTest < ActionView::TestCase 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 |