Feature #36320 » 0001v2-Fix-autoloading-plugin-classes.patch
| config/application.rb | ||
|---|---|---|
|
# for more options (same options as config.cache_store).
|
||
|
config.redmine_search_cache_store = :memory_store
|
||
|
config.redmine_plugin_directory = 'plugins'
|
||
|
# Configure log level here so that additional environment file
|
||
|
# can change it (environments/ENV.rb would take precedence over it)
|
||
|
config.log_level = Rails.env.production? ? :info : :debug
|
||
| config/environments/test.rb | ||
|---|---|---|
|
# config.action_view.annotate_rendered_view_with_filenames = true
|
||
|
config.secret_key_base = 'a secret token for running the tests'
|
||
|
# Change the plugin directory when testing.
|
||
|
config.redmine_plugin_directory = 'test/fixtures/plugins'
|
||
|
end
|
||
| lib/redmine/plugin_loader.rb | ||
|---|---|---|
|
class PluginLoader
|
||
|
# Absolute path to the directory where plugins are located
|
||
|
cattr_accessor :directory
|
||
|
self.directory = Rails.root.join('plugins')
|
||
|
self.directory = Rails.root.join Rails.application.config.redmine_plugin_directory
|
||
|
# Absolute path to the plublic directory where plugins assets are copied
|
||
|
cattr_accessor :public_directory
|
||
| ... | ... | |
|
# Add the plugin directories to rails autoload paths
|
||
|
engine_cfg = Rails::Engine::Configuration.new(directory.to_s)
|
||
|
engine_cfg.paths.add 'lib', eager_load: true
|
||
|
engine_cfg.eager_load_paths.each do |dir|
|
||
|
engine_cfg.paths.eager_load.each do |dir|
|
||
|
Rails.autoloaders.main.push_dir dir
|
||
|
Rails.application.config.watchable_dirs[dir] = [:rb]
|
||
|
end
|
||
| test/fixtures/plugins/foo_plugin/app/models/foo.rb | ||
|---|---|---|
|
# frozen_string_literal: true
|
||
|
class Foo < ActiveRecord::Base
|
||
|
end
|
||
| test/unit/lib/redmine/plugin_loader_test.rb | ||
|---|---|---|
|
def setup
|
||
|
clear_public
|
||
|
# Change plugin directory for testing to default in config/environments/tesr.rb.
|
||
|
# plugins/foo => test/fixtures/plugins/foo
|
||
|
@klass = Redmine::PluginLoader
|
||
|
@klass.directory = Rails.root.join('test/fixtures/plugins')
|
||
|
@klass.public_directory = Rails.root.join('tmp/public/plugin_assets')
|
||
|
@klass.load
|
||
|
end
|
||
| ... | ... | |
|
assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
|
||
|
end
|
||
|
def test_autoload
|
||
|
assert_equal true, Object.const_defined?(:Foo)
|
||
|
end
|
||
|
def clear_public
|
||
|
FileUtils.rm_rf 'tmp/public'
|
||
|
end
|
||
| test/unit/lib/redmine/plugin_test.rb | ||
|---|---|---|
|
class Redmine::PluginTest < ActiveSupport::TestCase
|
||
|
def setup
|
||
|
@klass = Redmine::Plugin
|
||
|
# Change plugin directory for testing to default
|
||
|
# Change plugin directory for testing to default in config/environments/tesr.rb.
|
||
|
# plugins/foo => test/fixtures/plugins/foo
|
||
|
@klass.directory = Rails.root.join('test/fixtures/plugins')
|
||
|
# In case some real plugins are installed
|
||
|
@klass.clear
|
||