Commits

Daniel Schierbeck  committed 4452849

Return an empty array if no tracker is found

  • Participants
  • Parent commits 9ca8c63

Comments (0)

Files changed (2)

File actionpack/lib/action_view/dependency_tracker.rb

     @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)

File actionpack/test/template/dependency_tracker_test.rb

 
 class DependencyTrackerTest < ActionView::TestCase
   Neckbeard = Class.new
+  Bowtie = Class.new
 
   class NeckbeardTracker
     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
 
     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