Feature #36320 » 0001v2-Fix-autoloading-plugin-classes.patch
config/application.rb | ||
---|---|---|
85 | 85 |
# for more options (same options as config.cache_store). |
86 | 86 |
config.redmine_search_cache_store = :memory_store |
87 | 87 | |
88 |
config.redmine_plugin_directory = 'plugins' |
|
89 | ||
88 | 90 |
# Configure log level here so that additional environment file |
89 | 91 |
# can change it (environments/ENV.rb would take precedence over it) |
90 | 92 |
config.log_level = Rails.env.production? ? :info : :debug |
config/environments/test.rb | ||
---|---|---|
71 | 71 |
# config.action_view.annotate_rendered_view_with_filenames = true |
72 | 72 | |
73 | 73 |
config.secret_key_base = 'a secret token for running the tests' |
74 | ||
75 |
# Change the plugin directory when testing. |
|
76 |
config.redmine_plugin_directory = 'test/fixtures/plugins' |
|
74 | 77 |
end |
lib/redmine/plugin_loader.rb | ||
---|---|---|
84 | 84 |
class PluginLoader |
85 | 85 |
# Absolute path to the directory where plugins are located |
86 | 86 |
cattr_accessor :directory |
87 |
self.directory = Rails.root.join('plugins')
|
|
87 |
self.directory = Rails.root.join Rails.application.config.redmine_plugin_directory
|
|
88 | 88 | |
89 | 89 |
# Absolute path to the plublic directory where plugins assets are copied |
90 | 90 |
cattr_accessor :public_directory |
... | ... | |
126 | 126 |
# Add the plugin directories to rails autoload paths |
127 | 127 |
engine_cfg = Rails::Engine::Configuration.new(directory.to_s) |
128 | 128 |
engine_cfg.paths.add 'lib', eager_load: true |
129 |
engine_cfg.eager_load_paths.each do |dir|
|
|
129 |
engine_cfg.paths.eager_load.each do |dir|
|
|
130 | 130 |
Rails.autoloaders.main.push_dir dir |
131 | 131 |
Rails.application.config.watchable_dirs[dir] = [:rb] |
132 | 132 |
end |
test/fixtures/plugins/foo_plugin/app/models/foo.rb | ||
---|---|---|
1 |
# frozen_string_literal: true |
|
2 | ||
3 |
class Foo < ActiveRecord::Base |
|
4 |
end |
test/unit/lib/redmine/plugin_loader_test.rb | ||
---|---|---|
23 | 23 |
def setup |
24 | 24 |
clear_public |
25 | 25 | |
26 |
# Change plugin directory for testing to default in config/environments/tesr.rb. |
|
27 |
# plugins/foo => test/fixtures/plugins/foo |
|
26 | 28 |
@klass = Redmine::PluginLoader |
27 |
@klass.directory = Rails.root.join('test/fixtures/plugins') |
|
28 | 29 |
@klass.public_directory = Rails.root.join('tmp/public/plugin_assets') |
29 | 30 |
@klass.load |
30 | 31 |
end |
... | ... | |
55 | 56 |
assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css") |
56 | 57 |
end |
57 | 58 | |
59 |
def test_autoload |
|
60 |
assert_equal true, Object.const_defined?(:Foo) |
|
61 |
end |
|
62 | ||
58 | 63 |
def clear_public |
59 | 64 |
FileUtils.rm_rf 'tmp/public' |
60 | 65 |
end |
test/unit/lib/redmine/plugin_test.rb | ||
---|---|---|
22 | 22 |
class Redmine::PluginTest < ActiveSupport::TestCase |
23 | 23 |
def setup |
24 | 24 |
@klass = Redmine::Plugin |
25 |
# Change plugin directory for testing to default |
|
25 |
# Change plugin directory for testing to default in config/environments/tesr.rb.
|
|
26 | 26 |
# plugins/foo => test/fixtures/plugins/foo |
27 |
@klass.directory = Rails.root.join('test/fixtures/plugins') |
|
27 | ||
28 | 28 |
# In case some real plugins are installed |
29 | 29 |
@klass.clear |
30 | 30 |