diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2024-02-27 07:22:51 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2024-02-27 07:22:51 +0000 |
commit | 26f3a4192a72c8656581f161ead123fd5d050921 (patch) | |
tree | 6bec30f247bd79b7dfeace8392edd89159bef173 | |
parent | 9985b73332b734f53c6c09f28e1eeeeb691d53ec (diff) | |
download | redmine-26f3a4192a72c8656581f161ead123fd5d050921.tar.gz redmine-26f3a4192a72c8656581f161ead123fd5d050921.zip |
Merged r22747 from trunk to 5.1-stable (#39948).
git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@22750 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/plugin.rb | 12 | ||||
-rw-r--r-- | test/unit/lib/redmine/plugin_test.rb | 8 |
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 79e310f31..07f04fc30 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -416,6 +416,18 @@ module Redmine Redmine::WikiFormatting.register(name, *args) end + # Register plugin models that use acts_as_attachable. + # + # Example: + # attachment_object_type SomeAttachableModel + # + # This is necessary for the core attachments controller routes and attachments/_form to work. + def attachment_object_type(*args) + args.each do |klass| + Redmine::Acts::Attachable::ObjectTypeConstraint.register_object_type(klass.name.underscore.pluralize) + end + end + # Returns +true+ if the plugin can be configured. def configurable? settings && settings.is_a?(Hash) && settings[:partial].present? diff --git a/test/unit/lib/redmine/plugin_test.rb b/test/unit/lib/redmine/plugin_test.rb index 02df23236..c1af3cdb0 100644 --- a/test/unit/lib/redmine/plugin_test.rb +++ b/test/unit/lib/redmine/plugin_test.rb @@ -62,6 +62,14 @@ class Redmine::PluginTest < ActiveSupport::TestCase assert_equal File.join(@klass.directory, 'foo_plugin', 'assets'), plugin.assets_directory end + ::FooModel = Class.new(ActiveRecord::Base) + def test_register_attachment_object_type + Redmine::Acts::Attachable::ObjectTypeConstraint.expects(:register_object_type).with("foo_models") + @klass.register :foo_plugin do + attachment_object_type FooModel + end + end + def test_register_should_raise_error_if_plugin_directory_does_not_exist e = assert_raises Redmine::PluginNotFound do @klass.register(:bar_plugin) {} |