aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2019-03-20 14:51:00 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2019-03-20 14:52:01 +0900
commite5d7b98fbd5f1903ac5e85a2bf85bb769789d570 (patch)
tree178f906d8033b18becca300046872e9ae71adf56 /railties/test/generators
parent7c6343078a566264ce6df6e531c9790ff2d2f432 (diff)
downloadrails-e5d7b98fbd5f1903ac5e85a2bf85bb769789d570.tar.gz
rails-e5d7b98fbd5f1903ac5e85a2bf85bb769789d570.tar.bz2
rails-e5d7b98fbd5f1903ac5e85a2bf85bb769789d570.zip
Make aliases of `database` 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#L53 But 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#L4 Follow up #34021.
Diffstat (limited to 'railties/test/generators')
-rw-r--r--railties/test/generators/migration_generator_test.rb11
-rw-r--r--railties/test/generators/model_generator_test.rb11
-rw-r--r--railties/test/generators/scaffold_generator_test.rb8
3 files changed, 30 insertions, 0 deletions
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb
index 5812cbdfc9..acc5fc3b25 100644
--- a/railties/test/generators/migration_generator_test.rb
+++ b/railties/test/generators/migration_generator_test.rb
@@ -265,6 +265,17 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_database_puts_migrations_in_configured_folder_with_aliases
+ with_secondary_database_configuration do
+ run_generator ["create_books", "--db=secondary"]
+ assert_migration "db/secondary_migrate/create_books.rb" do |content|
+ assert_method :change, content do |change|
+ assert_match(/create_table :books/, change)
+ end
+ end
+ end
+ end
+
def test_should_create_empty_migrations_if_name_not_start_with_add_or_remove_or_create
migration = "delete_books"
run_generator [migration, "title:string", "content:text"]
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index 134659f285..bdb430369e 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -403,6 +403,17 @@ class ModelGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_database_puts_migrations_in_configured_folder_with_aliases
+ with_secondary_database_configuration do
+ run_generator ["account", "--db=secondary"]
+ assert_migration "db/secondary_migrate/create_accounts.rb" do |content|
+ assert_method :change, content do |change|
+ assert_match(/create_table :accounts/, change)
+ end
+ end
+ end
+ end
+
def test_required_belongs_to_adds_required_association
run_generator ["account", "supplier:references{required}"]
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index f672e301a7..715ad938f4 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -479,6 +479,14 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_scaffold_generator_database_with_aliases
+ with_secondary_database_configuration do
+ run_generator ["posts", "--db=secondary"]
+
+ assert_migration "db/secondary_migrate/create_posts.rb"
+ end
+ end
+
def test_scaffold_generator_password_digest
run_generator ["user", "name", "password:digest"]