aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2019-06-05 10:31:52 -0400
committerGitHub <noreply@github.com>2019-06-05 10:31:52 -0400
commitccb30615a3b6d5fd78b94fe44155310854241f6a (patch)
tree855e4ee2752305f3c48b1358f934d56f508647c7 /railties
parent71a019efe8eaaac100640645d14ea6016fff2df7 (diff)
parent87796b3c8120becf583529756cbe5f36b4a3132c (diff)
downloadrails-ccb30615a3b6d5fd78b94fe44155310854241f6a.tar.gz
rails-ccb30615a3b6d5fd78b94fe44155310854241f6a.tar.bz2
rails-ccb30615a3b6d5fd78b94fe44155310854241f6a.zip
Merge pull request #36416 from freeletics/fix-db-prepare
Fixed db:prepare task for multiple databases.
Diffstat (limited to 'railties')
-rw-r--r--railties/test/application/rake/multi_dbs_test.rb20
-rw-r--r--railties/test/isolation/abstract_unit.rb42
2 files changed, 50 insertions, 12 deletions
diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb
index 31ea2246a9..8c41b252da 100644
--- a/railties/test/application/rake/multi_dbs_test.rb
+++ b/railties/test/application/rake/multi_dbs_test.rb
@@ -303,6 +303,26 @@ module ApplicationTests
require "#{app_path}/config/environment"
db_prepare
end
+
+ test "db:prepare setups missing database without clearing existing one" do
+ require "#{app_path}/config/environment"
+ Dir.chdir(app_path) do
+ # Bug not visible on SQLite3. Can be simplified when https://github.com/rails/rails/issues/36383 resolved
+ use_postgresql(multi_db: true)
+ generate_models_for_animals
+
+ rails "db:create:animals", "db:migrate:animals", "db:create:primary", "db:migrate:primary", "db:schema:dump"
+ rails "db:drop:primary"
+ Dog.create!
+ output = rails("db:prepare")
+
+ assert_match(/Created database/, output)
+ assert_equal 1, Dog.count
+ ensure
+ Dog.connection.disconnect!
+ rails "db:drop" rescue nil
+ end
+ end
end
end
end
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index fab704944b..0fe62df8ba 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -448,18 +448,36 @@ module TestHelpers
$:.reject! { |path| path =~ %r'/(#{to_remove.join('|')})/' }
end
- def use_postgresql
- File.open("#{app_path}/config/database.yml", "w") do |f|
- f.puts <<-YAML
- default: &default
- adapter: postgresql
- pool: 5
- database: railties_test
- development:
- <<: *default
- test:
- <<: *default
- YAML
+ def use_postgresql(multi_db: false)
+ if multi_db
+ File.open("#{app_path}/config/database.yml", "w") do |f|
+ f.puts <<-YAML
+ default: &default
+ adapter: postgresql
+ pool: 5
+ development:
+ primary:
+ <<: *default
+ database: railties_test
+ animals:
+ <<: *default
+ database: railties_animals_test
+ migrations_paths: db/animals_migrate
+ YAML
+ end
+ else
+ File.open("#{app_path}/config/database.yml", "w") do |f|
+ f.puts <<-YAML
+ default: &default
+ adapter: postgresql
+ pool: 5
+ database: railties_test
+ development:
+ <<: *default
+ test:
+ <<: *default
+ YAML
+ end
end
end
end