Project

General

Profile

Feature #39948 » 0001-introduces-Redmine-Plugin-attachment_object_type-399.patch

Jens Krämer, 2024-01-24 09:23

View differences:

lib/redmine/plugin.rb
416 416
      Redmine::WikiFormatting.register(name, *args)
417 417
    end
418 418

  
419
    # Register plugin models that use acts_as_attachable.
420
    #
421
    # Example:
422
    #   attachment_object_type SomeAttachableModel
423
    #
424
    # This is necessary for the core attachments controller routes and attachments/_form to work.
425
    def attachment_object_type(*args)
426
      args.each do |klass|
427
        Redmine::Acts::Attachable::ObjectTypeConstraint.register_object_type(klass.name.underscore.pluralize)
428
      end
429
    end
430

  
419 431
    # Returns +true+ if the plugin can be configured.
420 432
    def configurable?
421 433
      settings && settings.is_a?(Hash) && settings[:partial].present?
test/unit/lib/redmine/plugin_test.rb
62 62
    assert_equal File.join(@klass.directory, 'foo_plugin', 'assets'), plugin.assets_directory
63 63
  end
64 64

  
65
  ::FooModel = Class.new(ActiveRecord::Base)
66
  def test_register_attachment_object_type
67
    Redmine::Acts::Attachable::ObjectTypeConstraint.expects(:register_object_type).with("foo_models")
68
    @klass.register :foo_plugin do
69
      attachment_object_type FooModel
70
    end
71
  end
72

  
65 73
  def test_register_should_raise_error_if_plugin_directory_does_not_exist
66 74
    e = assert_raises Redmine::PluginNotFound do
67 75
      @klass.register(:bar_plugin) {}
    (1-1/1)