]> source.dussan.org Git - redmine.git/commitdiff
More unit tests for the plugins. Fixed bug where a plugin's hook method could return...
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 29 Jul 2008 00:10:22 +0000 (17:10 -0700)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 29 Jul 2008 00:10:22 +0000 (17:10 -0700)
lib/redmine/plugin.rb
test/unit/lib/redmine/plugin_hook_test.rb

index 70f7331b8e672b06d570a062d4871914279f60bc..d40a6caa28e9d1b303717d19ca3bd71d74f7f613 100644 (file)
@@ -203,7 +203,8 @@ module Redmine #:nodoc:
           def call_hook(hook_name, context = { })
             response = ''
             @@hooks[hook_name.to_sym].each do |method|
-              response += method.call(context)
+              method_response = method.call(context)
+              response += method_response unless method_response.nil?
             end
             response
           end
index 22b58541b31abca087a024de4850977858ac1aed..e07e89024ba03b5064cd86263f3eb369f19b5d13 100644 (file)
@@ -47,6 +47,53 @@ class Redmine::Plugin::Hook::ManagerTest < Test::Unit::TestCase
     @manager.add_listener(:issue_show, Proc.new { } )
     assert_equal 1, @manager::hooks[:issue_show].length
   end
+  
+  def test_add_invalid_listener
+    hooks = @manager::hooks
+    @manager.add_listener(:invalid, Proc.new { } )
+    assert_equal hooks, @manager::hooks
+  end
+  
+  def test_call_hook_with_response
+    function = Proc.new { return 'response' }
+    
+    @manager.add_listener(:issue_show, function)
+    
+    assert_equal 'response', @manager.call_hook(:issue_show)
+  end
+
+  def test_call_multiple_hooks_with_response
+    function1 = Proc.new { return 'First Call.' }
+    function2 = Proc.new { return 'Second Call.' }
+    function3 = Proc.new { return 'Third Call.' }
+    
+    @manager.add_listener(:issue_show, function1)
+    @manager.add_listener(:issue_show, function2)
+    @manager.add_listener(:issue_show, function3)
+    
+    assert_equal 'First Call.Second Call.Third Call.', @manager.call_hook(:issue_show)
+  end
+
+  def test_call_hook_without_response
+    function = Proc.new { }
+    
+    @manager.add_listener(:issue_show, function)
+    
+    assert_equal '', @manager.call_hook(:issue_show)
+  end
+
+   def test_call_multiple_hooks_without_responses
+     function1 = Proc.new { }
+     function2 = Proc.new { }
+     function3 = Proc.new { }
+    
+     @manager.add_listener(:issue_show, function1)
+     @manager.add_listener(:issue_show, function2)
+     @manager.add_listener(:issue_show, function3)
+    
+     assert_equal '', @manager.call_hook(:issue_show)
+   end
+
 end
 
 class Redmine::Plugin::Hook::BaseTest < Test::Unit::TestCase