More unit tests for the plugins. Fixed bug where a plugin's hook method could return nil.
This commit is contained in:
1 parent
e14b86453e
commit
ca8fb4026e
2 files changed
+49
-1
No files matched your search
@@ -203,7 +203,8 @@ module Redmine #:nodoc:
|
|||||||
def call_hook(hook_name, context = { })
|
def call_hook(hook_name, context = { })
|
||||||
response = ''
|
response = ''
|
||||||
@@hooks[hook_name.to_sym].each do |method|
|
@@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
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,6 +47,53 @@ class Redmine::Plugin::Hook::ManagerTest < Test::Unit::TestCase
|
|||||||
@manager.add_listener(:issue_show, Proc.new { } )
|
@manager.add_listener(:issue_show, Proc.new { } )
|
||||||
assert_equal 1, @manager::hooks[:issue_show].length
|
assert_equal 1, @manager::hooks[:issue_show].length
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class Redmine::Plugin::Hook::BaseTest < Test::Unit::TestCase
|
class Redmine::Plugin::Hook::BaseTest < Test::Unit::TestCase
|
||||||
|
|||||||
Reference in new issue
Block a user