Project

General

Profile

Defect #39834 » 0002-Extract-plugin-autoload-test.patch

Takashi Kato, 2023-12-12 13:49

View differences:

config/application.rb
# for more options (same options as config.cache_store).
config.redmine_search_cache_store = :memory_store
# Sets default plugin directory
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
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Change the plugin directory when testing to avoid clashes with real plugins.
config.redmine_plugin_directory = 'test/fixtures/plugins'
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
lib/redmine/plugin_loader.rb
class PluginLoader
# Absolute path to the directory where plugins are located
cattr_accessor :directory
self.directory = Rails.root.join Rails.application.config.redmine_plugin_directory
self.directory = Rails.root.join (ENV['REDMINE_PLUGINS_DIR'] || 'plugins')
# Absolute path to the public directory where plugins assets are copied
cattr_accessor :public_directory
lib/tasks/testing.rake
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_DIR"] = "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
test/autoload/plugin_autoload_test.rb
# 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_DIR']
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
test/integration/routing/plugins_test.rb
require File.expand_path('../../test_helper', __dir__)
class RoutingPluginsTest < Redmine::RoutingTest
def setup
# Change plugin loader's directory for testing
@original_plugin_dir = Redmine::PluginLoader.directory
Redmine::Plugin.clear
Redmine::PluginLoader.directory = Rails.root.join('test/fixtures/plugins')
Redmine::Plugin.directory = Rails.root.join('test/fixtures/plugins')
Redmine::PluginLoader.load
Redmine::PluginLoader.directories.each(&:run_initializer) # to define relative controllers
RedmineApp::Application.instance.routes_reloader.reload!
end
def teardown
Redmine::Plugin.clear
Redmine::PluginLoader.directory = @original_plugin_dir
Redmine::Plugin.directory = @original_plugin_dir
Redmine::PluginLoader.load
RedmineApp::Application.instance.routes_reloader.reload!
end
def test_plugins
should_route 'GET /plugin_articles' => 'plugin_articles#index'
should_route 'GET /bar_plugin_articles' => 'bar_plugin_articles#index'
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 in config/environments/test.rb.
# plugins/foo => test/fixtures/plugins/foo
@klass.directory = Rails.root.join('test/fixtures/plugins')
# In case some real plugins are installed
@klass.clear
(2-2/2)