DEV: Make setting up of multisite DB in test env clearer.

DEV: Make setting up of multisite DB in test env clearer.

diff --git a/config/database.yml b/config/database.yml
index edad118..a9be456 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -19,7 +19,7 @@ development:
 test:
   prepared_statements: false
   adapter: postgresql
-  database: "discourse_test<%= ENV['MULTISITE'] ? '_' + ENV['MULTISITE'] : '' %>"
+  database: <%= ENV["RAILS_DB"] ? ENV["RAILS_DB"] : "discourse_test" %>
   min_messages: warning
   pool: 5
   timeout: 5000
diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake
index f6fc6e6..ea9bcfc 100644
--- a/lib/tasks/db.rake
+++ b/lib/tasks/db.rake
@@ -7,32 +7,38 @@ task 'set_locale' do
   end
 end
 
-task 'db:environment:set', [:multisite] => [:load_config]  do |_, args|
-  if Rails.env.test? && !args[:multisite]
-    system("MULTISITE=multisite rails db:environment:set['true'] RAILS_ENV=test")
+module MultisiteTestHelpers
+  def self.load_multisite?
+    Rails.env.test? && !ENV["RAILS_DB"] && !ENV["SKIP_MULTISITE"]
   end
 end
 
-task 'db:create', [:multisite] => [:load_config] do |_, args|
-  if Rails.env.test? && !args[:multisite]
-    system("MULTISITE=multisite rails db:create['true']")
+task 'db:environment:set' => [:load_config]  do |_, args|
+  if MultisiteTestHelpers.load_multisite?
+    system("RAILS_ENV=test RAILS_DB=discourse_test_multisite rake db:environment:set")
   end
 end
 
-task 'db:drop', [:multisite] => [:load_config] do |_, args|
-  if Rails.env.test? && !args[:multisite]
-    system("MULTISITE=multisite rails db:drop['true']")
+task 'db:create' => [:load_config] do |_, args|
+  if MultisiteTestHelpers.load_multisite?
+    system("RAILS_DB=discourse_test_multisite rake db:create")
   end
 end
 
-# we need to run seed_fu every time we run rails db:migrate
-task 'db:migrate', [:multisite] => ['environment', 'set_locale'] do |_, args|
+task 'db:drop' => [:load_config] do |_, args|
+  if MultisiteTestHelpers.load_multisite?
+    system("RAILS_DB=discourse_test_multisite rake db:drop")
+  end
+end
+
+# we need to run seed_fu every time we run rake db:migrate
+task 'db:migrate' => ['environment', 'set_locale'] do |_, args|
   SeedFu.seed(DiscoursePluginRegistry.seed_paths)
 
-  if Rails.env.test? && !args[:multisite] && !ENV["SKIP_MULTISITE"]
-    system("rails db:schema:dump")
-    system("MULTISITE=multisite rails db:schema:load")
-    system("RAILS_DB=discourse_test_multisite rails db:migrate['multisite']")
+  if MultisiteTestHelpers.load_multisite?
+    system("rake db:schema:dump")
+    system("RAILS_DB=discourse_test_multisite rake db:schema:load")
+    system("RAILS_DB=discourse_test_multisite rake db:migrate")
   end
 end
 
diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake
index c60a7fb..d4f09ff 100644
--- a/lib/tasks/docker.rake
+++ b/lib/tasks/docker.rake
@@ -100,6 +100,9 @@ task 'docker:test' do
       @pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg")
 
       ENV["RAILS_ENV"] = "test"
+      # this shaves all the creation of the multisite db off
+      # for js tests
+      ENV["SKIP_MULTISITE"] = "1" if ENV["JS_ONLY"]
 
       @good &&= run_or_fail("bundle exec rake db:create")
 
@@ -107,10 +110,6 @@ task 'docker:test' do
         @good &&= run_or_fail("bundle exec rake plugin:install_all_official")
       end
 
-      # this shaves all the creation of the multisite db off
-      # for js tests
-      ENV["SKIP_MULTISITE"] = "1" if ENV["JS_ONLY"]
-
       if ENV["SKIP_PLUGINS"]
         @good &&= run_or_fail("bundle exec rake db:migrate")
       else

GitHub sha: 8e5e5d7d