Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromrails/rails

Commite5d7b98

Browse files
committed
Make aliases ofdatabase option in generators work
Thor automatically adds `-` if aliases do not start with `-`.https://github.com/erikhuda/thor/blob/0879c1773d188902d54f95174f33961ac33111f8/lib/thor/parser/options.rb#L53But Thor follows a convention of one-dash-one-letter options.So, even if `-` is added to `db`, it does not work.https://github.com/erikhuda/thor/blob/0879c1773d188902d54f95174f33961ac33111f8/lib/thor/parser/options.rb#L4Follow uprails#34021.
1 parent7c63430 commite5d7b98

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

‎activerecord/lib/rails/generators/active_record/migration/migration_generator.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MigrationGenerator < Base # :nodoc:
88
argument:attributes,type::array,default:[],banner:"field[:type][:index] field[:type][:index]"
99

1010
class_option:primary_key_type,type::string,desc:"The type for primary key"
11-
class_option:database,type::string,aliases:%i(db),desc:"The database for your migration. By default, the current environment's primary database is used."
11+
class_option:database,type::string,aliases:%i(--db),desc:"The database for your migration. By default, the current environment's primary database is used."
1212

1313
defcreate_migration_file
1414
set_local_assigns!

‎activerecord/lib/rails/generators/active_record/model/model_generator.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ModelGenerator < Base # :nodoc:
1414
class_option:parent,type::string,desc:"The parent class for the generated model"
1515
class_option:indexes,type::boolean,default:true,desc:"Add indexes for references and belongs_to columns"
1616
class_option:primary_key_type,type::string,desc:"The type for primary key"
17-
class_option:database,type::string,aliases:%i(db),desc:"The database for your model's migration. By default, the current environment's primary database is used."
17+
class_option:database,type::string,aliases:%i(--db),desc:"The database for your model's migration. By default, the current environment's primary database is used."
1818

1919
# creates the migration file for the model.
2020
defcreate_migration_file

‎railties/test/generators/migration_generator_test.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@ def test_database_puts_migrations_in_configured_folder
265265
end
266266
end
267267

268+
deftest_database_puts_migrations_in_configured_folder_with_aliases
269+
with_secondary_database_configurationdo
270+
run_generator["create_books","--db=secondary"]
271+
assert_migration"db/secondary_migrate/create_books.rb"do |content|
272+
assert_method:change,contentdo |change|
273+
assert_match(/create_table :books/,change)
274+
end
275+
end
276+
end
277+
end
278+
268279
deftest_should_create_empty_migrations_if_name_not_start_with_add_or_remove_or_create
269280
migration="delete_books"
270281
run_generator[migration,"title:string","content:text"]

‎railties/test/generators/model_generator_test.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ def test_database_puts_migrations_in_configured_folder
403403
end
404404
end
405405

406+
deftest_database_puts_migrations_in_configured_folder_with_aliases
407+
with_secondary_database_configurationdo
408+
run_generator["account","--db=secondary"]
409+
assert_migration"db/secondary_migrate/create_accounts.rb"do |content|
410+
assert_method:change,contentdo |change|
411+
assert_match(/create_table :accounts/,change)
412+
end
413+
end
414+
end
415+
end
416+
406417
deftest_required_belongs_to_adds_required_association
407418
run_generator["account","supplier:references{required}"]
408419

‎railties/test/generators/scaffold_generator_test.rb‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,14 @@ def test_scaffold_generator_database
479479
end
480480
end
481481

482+
deftest_scaffold_generator_database_with_aliases
483+
with_secondary_database_configurationdo
484+
run_generator["posts","--db=secondary"]
485+
486+
assert_migration"db/secondary_migrate/create_posts.rb"
487+
end
488+
end
489+
482490
deftest_scaffold_generator_password_digest
483491
run_generator["user","name","password:digest"]
484492

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp