From e566e60e51a740387261a06fe800fefece750fb1 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 17 Dec 2023 15:05:47 +0000 Subject: [PATCH] Adds test for plugin autoload issue (#36320, #39834). Patch by @tohosaku. git-svn-id: https://svn.redmine.org/redmine/trunk@22522 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- config/application.rb | 3 +++ config/environments/test.rb | 6 +++++ lib/redmine/plugin_loader.rb | 2 +- lib/tasks/testing.rake | 7 +++++ test/autoload/plugin_autoload_test.rb | 27 +++++++++++++++++++ .../plugins/foo_plugin/app/models/foo.rb | 3 +++ 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/autoload/plugin_autoload_test.rb create mode 100644 test/fixtures/plugins/foo_plugin/app/models/foo.rb diff --git a/config/application.rb b/config/application.rb index 48e855c9b..f3b6e82fd 100644 --- a/config/application.rb +++ b/config/application.rb @@ -85,6 +85,9 @@ module RedmineApp # for more options (same options as config.cache_store). config.redmine_search_cache_store = :memory_store + # Sets default plugin directory + config.redmine_plugins_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 diff --git a/config/environments/test.rb b/config/environments/test.rb index 2e7b23813..ea6080ac7 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,6 +18,12 @@ Rails.application.configure do # preloads Rails for running tests, you may have to set it to true. config.eager_load = false + # Change default plugins dir if env variable is present + # This is used by redmine plugins autoload test. + if ENV["REDMINE_PLUGINS_DIRECTORY"].present? + config.redmine_plugins_directory = ENV["REDMINE_PLUGINS_DIRECTORY"] + end + # 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 135df09ba..9f49208d6 100644 --- a/lib/redmine/plugin_loader.rb +++ b/lib/redmine/plugin_loader.rb @@ -84,7 +84,7 @@ module Redmine 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_plugins_directory # Absolute path to the public directory where plugins assets are copied cattr_accessor :public_directory diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index 5b5cedb46..2d946b355 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -114,4 +114,11 @@ namespace :test do Rails::TestUnit::Runner.run_from_rake 'test', FileList['test/integration/routing/*_test.rb'] + FileList['test/integration/api_test/*_routing_test.rb'] end Rake::Task['test:routing'].comment = "Run the routing tests" + + task(:autoload) do |t| + $: << "test" + ENV["REDMINE_PLUGINS_DIRECTORY"] = "test/fixtures/plugins" + Rails::TestUnit::Runner.run_from_rake 'test', FileList['test/autoload/*_test.rb'] + end + Rake::Task['test:autoload'].comment = "Run the plugin autoload tests" end diff --git a/test/autoload/plugin_autoload_test.rb b/test/autoload/plugin_autoload_test.rb new file mode 100644 index 000000000..76a1983d2 --- /dev/null +++ b/test/autoload/plugin_autoload_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true +# Redmine - project management software +# Copyright (C) 2006-2023 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require_relative '../test_helper' +class Redmine::PluginAutoloadTest < ActiveSupport::TestCase + if ENV['REDMINE_PLUGINS_DIRECTORY'] + def test_autoload + assert_equal true, Object.const_defined?(:Foo) + end + else + puts 'Tests related to plugin autoloading should be run separately using "rails test:autoload"' + end +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..0152b6e1a --- /dev/null +++ b/test/fixtures/plugins/foo_plugin/app/models/foo.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true +class Foo < ActiveRecord::Base +end -- 2.39.5