diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-10-04 15:30:50 -0400 |
---|---|---|
committer | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2018-10-09 16:40:06 -0400 |
commit | 287c0de8a10d070098a59f4be2772291c7b67576 (patch) | |
tree | 9b827f9d41fe9bc24ff678df5ba41942fe76cc93 /railties/test/application | |
parent | 92ccb7c75fd0d07479ea3b458b405b8e6667e05f (diff) | |
download | rails-287c0de8a10d070098a59f4be2772291c7b67576.tar.gz rails-287c0de8a10d070098a59f4be2772291c7b67576.tar.bz2 rails-287c0de8a10d070098a59f4be2772291c7b67576.zip |
Add multi-db support to rails db:migrate:status
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/rake/multi_dbs_test.rb | 70 |
1 files changed, 51 insertions, 19 deletions
diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb index bc6708c89e..6478e06250 100644 --- a/railties/test/application/rake/multi_dbs_test.rb +++ b/railties/test/application/rake/multi_dbs_test.rb @@ -55,11 +55,19 @@ module ApplicationTests end end - def db_migrate_and_schema_dump_and_load(namespace, expected_database, format) + def db_migrate_and_migrate_status Dir.chdir(app_path) do - rails "generate", "model", "book", "title:string" - rails "generate", "model", "dog", "name:string" - write_models_for_animals + generate_models_for_animals + rails "db:migrate" + output = rails "db:migrate:status" + assert_match(/up \d+ Create books/, output) + assert_match(/up \d+ Create dogs/, output) + end + end + + def db_migrate_and_schema_dump_and_load(format) + Dir.chdir(app_path) do + generate_models_for_animals rails "db:migrate", "db:#{format}:dump" if format == "schema" @@ -86,9 +94,7 @@ module ApplicationTests def db_migrate_namespaced(namespace, expected_database) Dir.chdir(app_path) do - rails "generate", "model", "book", "title:string" - rails "generate", "model", "dog", "name:string" - write_models_for_animals + generate_models_for_animals output = rails("db:migrate:#{namespace}") if namespace == "primary" assert_match(/CreateBooks: migrated/, output) @@ -98,6 +104,18 @@ module ApplicationTests end end + def db_migrate_status_namespaced(namespace, expected_database) + Dir.chdir(app_path) do + generate_models_for_animals + output = rails("db:migrate:status:#{namespace}") + if namespace == "primary" + assert_match(/up \d+ Create books/, output) + else + assert_match(/up \d+ Create dogs/, output) + end + end + end + def write_models_for_animals # make a directory for the animals migration FileUtils.mkdir_p("#{app_path}/db/animals_migrate") @@ -117,17 +135,22 @@ module ApplicationTests # create the base model for dog to inherit from File.open("#{app_path}/app/models/animals_base.rb", "w") do |file| - file.write(<<-EOS -class AnimalsBase < ActiveRecord::Base - self.abstract_class = true + file.write(<<~EOS) + class AnimalsBase < ActiveRecord::Base + self.abstract_class = true - establish_connection :animals -end -EOS -) + establish_connection :animals + end + EOS end end + def generate_models_for_animals + rails "generate", "model", "book", "title:string" + rails "generate", "model", "dog", "name:string" + write_models_for_animals + end + test "db:create and db:drop works on all databases for env" do require "#{app_path}/config/environment" ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| @@ -144,22 +167,31 @@ EOS test "db:migrate and db:schema:dump and db:schema:load works on all databases" do require "#{app_path}/config/environment" - ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| - db_migrate_and_schema_dump_and_load db_config.spec_name, db_config.config["database"], "schema" - end + db_migrate_and_schema_dump_and_load "schema" end test "db:migrate and db:structure:dump and db:structure:load works on all databases" do require "#{app_path}/config/environment" + db_migrate_and_schema_dump_and_load "structure" + end + + test "db:migrate:namespace works" do + require "#{app_path}/config/environment" ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| - db_migrate_and_schema_dump_and_load db_config.spec_name, db_config.config["database"], "structure" + db_migrate_namespaced db_config.spec_name, db_config.config["database"] end end - test "db:migrate:namespace works" do + test "db:migrate:status works on all databases" do + require "#{app_path}/config/environment" + db_migrate_and_migrate_status + end + + test "db:migrate:status:namespace works" do require "#{app_path}/config/environment" ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| db_migrate_namespaced db_config.spec_name, db_config.config["database"] + db_migrate_status_namespaced db_config.spec_name, db_config.config["database"] end end end |