Project

General

Profile

Patch #42934 ยป redmine-oss-52d298c-20250627.patch

Haruka Asakura (Agileware), 2025-06-27 13:38

View differences:

test/generators/controller_generator_test.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-  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
require_relative '../../lib/generators/redmine_plugin_controller/redmine_plugin_controller_generator'
22

  
23
class ControllerGeneratorTest < Rails::Generators::TestCase
24
  TMP_DIR = Rails.root / 'tmp/test/generators'
25

  
26
  tests RedminePluginControllerGenerator
27
  destination TMP_DIR
28
  setup :prepare_destination
29

  
30
  setup do
31
    @plugin_directory = Redmine::Plugin.directory
32
    Redmine::Plugin.directory = TMP_DIR
33
  end
34

  
35
  teardown do
36
    Redmine::Plugin.directory = @plugin_directory
37
  end
38

  
39
  def test_generates_files_from_templates
40
    g = generator ['ControllerDemo', 'Todo']
41

  
42
    assert_name g, 'Todo', :controller
43

  
44
    capture(:stdout) do
45
      g.copy_templates
46
    end
47

  
48
    controller_path_names = (Redmine::Plugin.directory / 'controller_demo/app/controllers')
49
      .glob('*.rb')
50
    assert_equal 1, controller_path_names.count
51
    assert_equal 'todo_controller.rb', controller_path_names.first.basename.to_s
52

  
53
    helper_path_names = (Redmine::Plugin.directory / 'controller_demo/app/helpers')
54
      .glob('*.rb')
55
    assert_equal 1, helper_path_names.count
56
    assert_equal 'todo_helper.rb', helper_path_names.first.basename.to_s
57

  
58
    test_path_names = (Redmine::Plugin.directory / 'controller_demo/test/functional')
59
      .glob('*.rb')
60
    assert_equal 1, test_path_names.count
61
    assert_equal 'todo_controller_test.rb', test_path_names.first.basename.to_s
62
  end
63

  
64
  private
65

  
66
  def assert_name(generator, value, method)
67
    assert_equal value, generator.send(method)
68
  end
69
end
test/generators/model_generator_test.rb
1
# frozen_string_literal: true
2

  
3
# Redmine - project management software
4
# Copyright (C) 2006-  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
require_relative '../../lib/generators/redmine_plugin_model/redmine_plugin_model_generator'
22

  
23
class ModelGeneratorTest < Rails::Generators::TestCase
24
  TMP_DIR = Rails.root / 'tmp/test/generators'
25

  
26
  tests RedminePluginModelGenerator
27
  destination TMP_DIR
28
  setup :prepare_destination
29

  
30
  setup do
31
    @plugin_directory = Redmine::Plugin.directory
32
    Redmine::Plugin.directory = TMP_DIR
33
  end
34

  
35
  teardown do
36
    Redmine::Plugin.directory = @plugin_directory
37
  end
38

  
39
  def test_generates_files_from_templates
40
    g = generator ['ModelDemo', 'TodoModel']
41

  
42
    assert_name g, 'TodoModel', :model
43

  
44
    capture(:stdout) do
45
      g.copy_templates
46
    end
47

  
48
    model_path_names = (Redmine::Plugin.directory / 'model_demo/app/models')
49
      .glob('*.rb')
50
    assert_equal 1, model_path_names.count
51
    assert_equal 'todo_model.rb', model_path_names.first.basename.to_s
52

  
53
    test_path_names = (Redmine::Plugin.directory / 'model_demo/test/unit')
54
      .glob('*.rb')
55
    assert_equal 1, test_path_names.count
56
    assert_equal 'todo_model_test.rb', test_path_names.first.basename.to_s
57

  
58
    migration_path_names = (Redmine::Plugin.directory / 'model_demo/db/migrate')
59
      .glob('*.rb')
60
    assert_equal 1, migration_path_names.count
61
    assert_match(/\d+_create_todo_models\.rb/, migration_path_names.first.basename.to_s)
62
  end
63

  
64
  private
65

  
66
  def assert_name(generator, value, method)
67
    assert_equal value, generator.send(method)
68
  end
69
end
    (1-1/1)