Feature #28412 ยป redmine_plugin_register.patch
lib/redmine/plugin.rb | ||
---|---|---|
19 | 19 | |
20 | 20 |
class PluginNotFound < StandardError; end |
21 | 21 |
class PluginRequirementError < StandardError; end |
22 |
class PluginIdDuplicated < StandardError; end |
|
22 | 23 | |
23 | 24 |
# Base class for Redmine plugins. |
24 | 25 |
# Plugins are registered using the <tt>register</tt> class method that acts as the public constructor. |
... | ... | |
72 | 73 |
# Plugin constructor |
73 | 74 |
def self.register(id, &block) |
74 | 75 |
p = new(id) |
76 |
if installed?(p.id) |
|
77 |
raise PluginIdDuplicated.new("#{p.id} plugin was already registered.") |
|
78 |
end |
|
75 | 79 |
p.instance_eval(&block) |
76 | 80 | |
77 | 81 |
# Set a default name if it was not provided during registration |
... | ... | |
152 | 156 |
end |
153 | 157 |
initializer = File.join(directory, "init.rb") |
154 | 158 |
if File.file?(initializer) |
155 |
require initializer |
|
159 |
begin |
|
160 |
require initializer |
|
161 |
rescue => e |
|
162 |
Rails.logger.warn("plugin loading failed. skip loading. message: #{e.message}") |
|
163 |
end |
|
156 | 164 |
end |
157 | 165 |
end |
158 | 166 |
end |
test/functional/settings_controller_test.rb | ||
---|---|---|
29 | 29 |
def teardown |
30 | 30 |
Setting.delete_all |
31 | 31 |
Setting.clear_cache |
32 |
Redmine::Plugin.clear |
|
32 | 33 |
end |
33 | 34 | |
34 | 35 |
def test_index |
test/unit/lib/redmine/plugin_test.rb | ||
---|---|---|
52 | 52 |
assert_equal '0.0.1', plugin.version |
53 | 53 |
end |
54 | 54 | |
55 |
def test_register_fail |
|
56 |
@klass.register :foo do |
|
57 |
name 'Foo plugin' |
|
58 |
url 'http://example.net/plugins/foo' |
|
59 |
author 'John Smith' |
|
60 |
author_url 'http://example.net/jsmith' |
|
61 |
version '0.0.1' |
|
62 |
end |
|
63 | ||
64 |
assert_equal 1, @klass.all.size |
|
65 | ||
66 |
assert_raise Redmine::PluginIdDuplicated do |
|
67 |
@klass.register :foo do |
|
68 |
name 'Yet Another Foo plugin' |
|
69 |
url 'http://example.net/plugins/ya_foo' |
|
70 |
author 'Joe Bloggs' |
|
71 |
author_url 'http://example.net/jbloggs' |
|
72 |
version '1.0.0' |
|
73 |
end |
|
74 |
end |
|
75 |
assert_equal 1, @klass.all.size |
|
76 | ||
77 |
assert_nothing_raised do |
|
78 |
@klass.register :ya_foo do |
|
79 |
name 'Yet Another Foo plugin' |
|
80 |
url 'http://example.net/plugins/ya_foo' |
|
81 |
author 'Joe Bloggs' |
|
82 |
author_url 'http://example.net/jbloggs' |
|
83 |
version '1.0.0' |
|
84 |
end |
|
85 |
end |
|
86 |
assert_equal 2, @klass.all.size |
|
87 |
end |
|
88 | ||
55 | 89 |
def test_installed |
56 | 90 |
@klass.register(:foo) {} |
57 | 91 |
assert_equal true, @klass.installed?(:foo) |