aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/rake/multi_dbs_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/application/rake/multi_dbs_test.rb')
-rw-r--r--railties/test/application/rake/multi_dbs_test.rb105
1 files changed, 84 insertions, 21 deletions
diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb
index bc6708c89e..ef99365e75 100644
--- a/railties/test/application/rake/multi_dbs_test.rb
+++ b/railties/test/application/rake/multi_dbs_test.rb
@@ -55,11 +55,40 @@ 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_cache_dump
+ Dir.chdir(app_path) do
+ generate_models_for_animals
+ rails "db:migrate"
+ rails "db:schema:cache:dump"
+ assert File.exist?("db/schema_cache.yml")
+ assert File.exist?("db/animals_schema_cache.yml")
+ end
+ end
+
+ def db_migrate_and_schema_cache_dump_and_schema_cache_clear
+ Dir.chdir(app_path) do
+ generate_models_for_animals
+ rails "db:migrate"
+ rails "db:schema:cache:dump"
+ rails "db:schema:cache:clear"
+ assert_not File.exist?("db/schema_cache.yml")
+ assert_not File.exist?("db/animals_schema_cache.yml")
+ 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"
@@ -84,11 +113,9 @@ module ApplicationTests
end
end
- def db_migrate_namespaced(namespace, expected_database)
+ def db_migrate_namespaced(namespace)
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 +125,18 @@ module ApplicationTests
end
end
+ def db_migrate_status_namespaced(namespace)
+ 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 +156,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,24 +188,43 @@ 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
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_namespaced db_config.spec_name
+ db_migrate_status_namespaced db_config.spec_name
end
end
+
+ test "db:schema:cache:dump works on all databases" do
+ require "#{app_path}/config/environment"
+ db_migrate_and_schema_cache_dump
+ end
+
+ test "db:schema:cache:clear works on all databases" do
+ require "#{app_path}/config/environment"
+ db_migrate_and_schema_cache_dump_and_schema_cache_clear
+ end
end
end
end