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

This commit is contained in:
Guo Xiang Tan 2019-03-21 09:50:16 +08:00
parent 600313373b
commit 8e5e5d7d35
3 changed files with 25 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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