Project

General

Profile

Feature #38730 » fix-migration-file-name-to-snake-case.patch

[Agileware]Haruka Asakura, 2023-06-16 06:37

View differences:

lib/generators/redmine_plugin_migration/redmine_plugin_migration_generator.rb
34 34
    plugin_name = file_name.underscore
35 35
    plugin_path = File.join(Redmine::Plugin.directory, plugin_name)
36 36
    migration_template "migration.rb",
37
                       "#{plugin_path}/db/migrate/#{@migration}.rb"
37
                       "#{plugin_path}/db/migrate/#{@migration.underscore}.rb"
38 38
  end
39 39
end
test/generators/migration_generator_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
require_relative '../../lib/generators/redmine_plugin_migration/redmine_plugin_migration_generator'
22

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

  
26
  tests RedminePluginMigrationGenerator
27
  destination TMP_DIR
28
  setup :prepare_destination
29

  
30
  def test_migration_file_name_is_snake_case
31
    g = generator ['MigrationDemo', 'AddMigrationTable']
32
    Redmine::Plugin.directory = TMP_DIR
33

  
34
    assert_name g, 'AddMigrationTable', :migration
35

  
36
    capture(:stdout) do
37
      g.create_migration_file
38
    end
39

  
40
    path_names = (Redmine::Plugin.directory / 'migration_demo/db/migrate')
41
      .glob('*_add_migration_table.rb')
42

  
43
    assert_equal 1, path_names.count
44
  end
45

  
46
  private
47
  def assert_name(generator, value, method)
48
    assert_equal value, generator.send(method)
49
  end
50
end
(1-1/2)