Feature #28412 ยป redmine_plugin_register.patch
| lib/redmine/plugin.rb | ||
|---|---|---|
|
class PluginNotFound < StandardError; end
|
||
|
class PluginRequirementError < StandardError; end
|
||
|
class PluginIdDuplicated < StandardError; end
|
||
|
# Base class for Redmine plugins.
|
||
|
# Plugins are registered using the <tt>register</tt> class method that acts as the public constructor.
|
||
| ... | ... | |
|
# Plugin constructor
|
||
|
def self.register(id, &block)
|
||
|
p = new(id)
|
||
|
if installed?(p.id)
|
||
|
raise PluginIdDuplicated.new("#{p.id} plugin was already registered.")
|
||
|
end
|
||
|
p.instance_eval(&block)
|
||
|
# Set a default name if it was not provided during registration
|
||
| ... | ... | |
|
end
|
||
|
initializer = File.join(directory, "init.rb")
|
||
|
if File.file?(initializer)
|
||
|
require initializer
|
||
|
begin
|
||
|
require initializer
|
||
|
rescue => e
|
||
|
Rails.logger.warn("plugin loading failed. skip loading. message: #{e.message}")
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| test/functional/settings_controller_test.rb | ||
|---|---|---|
|
def teardown
|
||
|
Setting.delete_all
|
||
|
Setting.clear_cache
|
||
|
Redmine::Plugin.clear
|
||
|
end
|
||
|
def test_index
|
||
| test/unit/lib/redmine/plugin_test.rb | ||
|---|---|---|
|
assert_equal '0.0.1', plugin.version
|
||
|
end
|
||
|
def test_register_fail
|
||
|
@klass.register :foo do
|
||
|
name 'Foo plugin'
|
||
|
url 'http://example.net/plugins/foo'
|
||
|
author 'John Smith'
|
||
|
author_url 'http://example.net/jsmith'
|
||
|
version '0.0.1'
|
||
|
end
|
||
|
assert_equal 1, @klass.all.size
|
||
|
assert_raise Redmine::PluginIdDuplicated do
|
||
|
@klass.register :foo do
|
||
|
name 'Yet Another Foo plugin'
|
||
|
url 'http://example.net/plugins/ya_foo'
|
||
|
author 'Joe Bloggs'
|
||
|
author_url 'http://example.net/jbloggs'
|
||
|
version '1.0.0'
|
||
|
end
|
||
|
end
|
||
|
assert_equal 1, @klass.all.size
|
||
|
assert_nothing_raised do
|
||
|
@klass.register :ya_foo do
|
||
|
name 'Yet Another Foo plugin'
|
||
|
url 'http://example.net/plugins/ya_foo'
|
||
|
author 'Joe Bloggs'
|
||
|
author_url 'http://example.net/jbloggs'
|
||
|
version '1.0.0'
|
||
|
end
|
||
|
end
|
||
|
assert_equal 2, @klass.all.size
|
||
|
end
|
||
|
def test_installed
|
||
|
@klass.register(:foo) {}
|
||
|
assert_equal true, @klass.installed?(:foo)
|
||