Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Return an empty array if no tracker is found

  • Loading branch information...
commit 445284906476f03acf37cab2b7dc265a985531c3 1 parent 9ca8c63
@dasch dasch authored
View
9 actionpack/lib/action_view/dependency_tracker.rb
@@ -5,8 +5,13 @@ class DependencyTracker
@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)
View
11 actionpack/test/template/dependency_tracker_test.rb
@@ -3,6 +3,7 @@
class DependencyTrackerTest < ActionView::TestCase
Neckbeard = Class.new
+ Bowtie = Class.new
class NeckbeardTracker
def self.call(name, template)
@@ -13,8 +14,8 @@ def self.call(name, template)
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 @@ def test_finds_tracker_by_template_handler
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
Please sign in to comment.
Something went wrong with that request. Please try again.