From 6d5becd59c1e289db9fe4cc1eaa84fc99374c93a Mon Sep 17 00:00:00 2001
From: Takashi Kato <tohosaku@users.osdn.me>
Date: Tue, 28 Nov 2023 10:48:29 +0000
Subject: [PATCH] Fix autoloading plugin classes

---
 config/environments/test.rb                        | 2 ++
 lib/redmine/plugin_loader.rb                       | 2 +-
 test/fixtures/plugins/foo_plugin/app/models/foo.rb | 4 ++++
 test/unit/lib/redmine/plugin_loader_test.rb        | 5 +++++
 4 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 test/fixtures/plugins/foo_plugin/app/models/foo.rb

diff --git a/config/environments/test.rb b/config/environments/test.rb
index 199f1bb27..1b63a5df7 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -18,6 +18,8 @@ Rails.application.configure do
   # preloads Rails for running tests, you may have to set it to true.
   config.eager_load = false
 
+  config.enable_reloading = true
+
   # Configure public file server for tests with Cache-Control for performance.
   config.public_file_server.enabled = true
   config.public_file_server.headers = {
diff --git a/lib/redmine/plugin_loader.rb b/lib/redmine/plugin_loader.rb
index 2151e949b..d136bff2b 100644
--- a/lib/redmine/plugin_loader.rb
+++ b/lib/redmine/plugin_loader.rb
@@ -126,7 +126,7 @@ module Redmine
         # 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
diff --git a/test/fixtures/plugins/foo_plugin/app/models/foo.rb b/test/fixtures/plugins/foo_plugin/app/models/foo.rb
new file mode 100644
index 000000000..db4a60096
--- /dev/null
+++ b/test/fixtures/plugins/foo_plugin/app/models/foo.rb
@@ -0,0 +1,4 @@
+# frozen_string_literal: true
+
+class Foo < ActiveRecord::Base
+end
diff --git a/test/unit/lib/redmine/plugin_loader_test.rb b/test/unit/lib/redmine/plugin_loader_test.rb
index ed5943346..e16c8b788 100644
--- a/test/unit/lib/redmine/plugin_loader_test.rb
+++ b/test/unit/lib/redmine/plugin_loader_test.rb
@@ -27,6 +27,7 @@ class Redmine::PluginLoaderTest < ActiveSupport::TestCase
     @klass.directory = Rails.root.join('test/fixtures/plugins')
     @klass.public_directory = Rails.root.join('tmp/public/plugin_assets')
     @klass.load
+    Rails.autoloaders.main.reload
   end
 
   def teardown
@@ -55,6 +56,10 @@ class Redmine::PluginLoaderTest < ActiveSupport::TestCase
     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
-- 
2.39.2

