aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2018-09-28 13:36:06 -0400
committerGannon McGibbon <gannon.mcgibbon@gmail.com>2018-09-28 14:24:36 -0400
commit4775d3d051af1a506b63a7e4069c94e49c82177d (patch)
treebd4dfbe583b86ee24e2548b83cc50f323891a918 /railties/test/generators
parent7d89337b1722587961b9bb81031661b99935d919 (diff)
downloadrails-4775d3d051af1a506b63a7e4069c94e49c82177d.tar.gz
rails-4775d3d051af1a506b63a7e4069c94e49c82177d.tar.bz2
rails-4775d3d051af1a506b63a7e4069c94e49c82177d.zip
Refactor migrations_path command option to database
Diffstat (limited to 'railties/test/generators')
-rw-r--r--railties/test/generators/generators_test_helper.rb14
-rw-r--r--railties/test/generators/migration_generator_test.rb12
-rw-r--r--railties/test/generators/model_generator_test.rb12
-rw-r--r--railties/test/generators/scaffold_generator_test.rb8
4 files changed, 33 insertions, 13 deletions
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index ad2a55f496..355d4b09a8 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -42,6 +42,20 @@ module GeneratorsTestHelper
end
end
+ def with_secondary_database_configuration
+ ActiveRecord::Base.configurations = {
+ test: {
+ secondary: {
+ database: "db/secondary.sqlite3",
+ migrations_paths: "db/secondary_migrate",
+ },
+ },
+ }
+ yield
+ ensure
+ ActiveRecord::Base.configurations = {}
+ end
+
def copy_routes
routes = File.expand_path("../../lib/rails/generators/rails/app/templates/config/routes.rb.tt", __dir__)
destination = File.join(destination_root, "config")
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb
index 5c57d607fc..5812cbdfc9 100644
--- a/railties/test/generators/migration_generator_test.rb
+++ b/railties/test/generators/migration_generator_test.rb
@@ -254,11 +254,13 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
end
end
- def test_migrations_paths_puts_migrations_in_that_folder
- run_generator ["create_books", "--migrations_paths=db/test_migrate"]
- assert_migration "db/test_migrate/create_books.rb" do |content|
- assert_method :change, content do |change|
- assert_match(/create_table :books/, change)
+ def test_database_puts_migrations_in_configured_folder
+ with_secondary_database_configuration do
+ run_generator ["create_books", "--database=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
diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb
index 5a0c2f74c7..b06db6dd8a 100644
--- a/railties/test/generators/model_generator_test.rb
+++ b/railties/test/generators/model_generator_test.rb
@@ -392,11 +392,13 @@ class ModelGeneratorTest < Rails::Generators::TestCase
end
end
- def test_migrations_paths_puts_migrations_in_that_folder
- run_generator ["account", "--migrations_paths=db/test_migrate"]
- assert_migration "db/test_migrate/create_accounts.rb" do |content|
- assert_method :change, content do |change|
- assert_match(/create_table :accounts/, change)
+ def test_database_puts_migrations_in_configured_folder
+ with_secondary_database_configuration do
+ run_generator ["account", "--database=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
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index dbcf49290e..94aab15aa9 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -476,10 +476,12 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
end
end
- def test_scaffold_generator_migrations_paths
- run_generator ["posts", "--migrations-paths=db/kingston_migrate"]
+ def test_scaffold_generator_database
+ with_secondary_database_configuration do
+ run_generator ["posts", "--database=secondary"]
- assert_migration "db/kingston_migrate/create_posts.rb"
+ assert_migration "db/secondary_migrate/create_posts.rb"
+ end
end
def test_scaffold_generator_password_digest