Project

General

Profile

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

Takashi Kato, 2023-12-12 13:49

View differences:

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
    # Sets default plugin directory
89
    config.redmine_plugin_directory = 'plugins'
90

  
91 88
    # Configure log level here so that additional environment file
92 89
    # can change it (environments/ENV.rb would take precedence over it)
93 90
    config.log_level = Rails.env.production? ? :info : :debug
config/environments/test.rb
18 18
  # preloads Rails for running tests, you may have to set it to true.
19 19
  config.eager_load = false
20 20

  
21
  # Change the plugin directory when testing to avoid clashes with real plugins.
22
  config.redmine_plugin_directory = 'test/fixtures/plugins'
23

  
24 21
  # Configure public file server for tests with Cache-Control for performance.
25 22
  config.public_file_server.enabled = true
26 23
  config.public_file_server.headers = {
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 Rails.application.config.redmine_plugin_directory
87
    self.directory = Rails.root.join (ENV['REDMINE_PLUGINS_DIR'] || 'plugins')
88 88

  
89 89
    # Absolute path to the public directory where plugins assets are copied
90 90
    cattr_accessor :public_directory
lib/tasks/testing.rake
114 114
    Rails::TestUnit::Runner.run_from_rake 'test', FileList['test/integration/routing/*_test.rb'] + FileList['test/integration/api_test/*_routing_test.rb']
115 115
  end
116 116
  Rake::Task['test:routing'].comment = "Run the routing tests"
117

  
118
  task(:autoload) do |t|
119
    $: << "test"
120
    ENV["REDMINE_PLUGINS_DIR"] = "test/fixtures/plugins"
121
    Rails::TestUnit::Runner.run_from_rake 'test', FileList['test/autoload/*_test.rb']
122
  end
123
  Rake::Task['test:autoload'].comment = "Run the plugin autoload tests"
117 124
end
test/autoload/plugin_autoload_test.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-2023  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require_relative '../test_helper'
21

  
22
class Redmine::PluginAutoloadTest < ActiveSupport::TestCase
23

  
24
  if ENV['REDMINE_PLUGINS_DIR']
25
    def test_autoload
26
      assert_equal true, Object.const_defined?(:Foo)
27
    end
28
  else
29
    puts 'Tests related to plugin autoloading should be run separately using "rails test:autoload"'
30
  end
31
end
test/integration/routing/plugins_test.rb
20 20
require File.expand_path('../../test_helper', __dir__)
21 21

  
22 22
class RoutingPluginsTest < Redmine::RoutingTest
23

  
24
  def setup
25
    # Change plugin loader's directory for testing
26
    @original_plugin_dir = Redmine::PluginLoader.directory
27
    Redmine::Plugin.clear
28
    Redmine::PluginLoader.directory = Rails.root.join('test/fixtures/plugins')
29
    Redmine::Plugin.directory = Rails.root.join('test/fixtures/plugins')
30
    Redmine::PluginLoader.load
31
    Redmine::PluginLoader.directories.each(&:run_initializer) # to define relative controllers
32
    RedmineApp::Application.instance.routes_reloader.reload!
33
  end
34

  
35
  def teardown
36
    Redmine::Plugin.clear
37
    Redmine::PluginLoader.directory = @original_plugin_dir
38
    Redmine::Plugin.directory = @original_plugin_dir
39
    Redmine::PluginLoader.load
40
    RedmineApp::Application.instance.routes_reloader.reload!
41
  end
42

  
23 43
  def test_plugins
24 44
    should_route 'GET /plugin_articles' => 'plugin_articles#index'
25 45
    should_route 'GET /bar_plugin_articles' => 'bar_plugin_articles#index'
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 26
    # plugins/foo => test/fixtures/plugins/foo
28 27
    @klass = Redmine::PluginLoader
28
    @klass.directory = Rails.root.join('test/fixtures/plugins')
29 29
    @klass.public_directory = Rails.root.join('tmp/public/plugin_assets')
30 30
    @klass.load
31 31
  end
......
56 56
    assert File.exist?("#{@klass.public_directory}/foo_plugin/stylesheets/foo.css")
57 57
  end
58 58

  
59
  def test_autoload
60
    assert_equal true, Object.const_defined?(:Foo)
61
  end
62

  
63 59
  def clear_public
64 60
    FileUtils.rm_rf 'tmp/public'
65 61
  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 in config/environments/test.rb.
26 25
    # plugins/foo => test/fixtures/plugins/foo
26
    @klass.directory = Rails.root.join('test/fixtures/plugins')
27 27
    # In case some real plugins are installed
28 28
    @klass.clear
29 29

  
(2-2/2)