From 21f8064781209bdcf685e356f5fe7c1fd120f045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Tue, 2 Feb 2021 15:18:53 -0500 Subject: [PATCH] Fix rake test:db loading in development Not setting the test environment for test tasks caused the test:db task to establish connection with the development environment. This fixes it by running the prerequisite rake tasks in a process with RAILS_ENV set to test. Co-authored-by: Adrianna Chang --- railties/lib/rails/test_unit/testing.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index bce1256507..e470f06b9c 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -24,7 +24,10 @@ namespace :test do task run: %w[test] desc "Run tests quickly, but also reset db" - task db: %w[db:test:prepare test] + task :db do + success = system({ "RAILS_ENV" => ENV.fetch("RAILS_ENV", "test") }, "rake", "db:test:prepare", "test") + success || exit(false) + end ["models", "helpers", "channels", "controllers", "mailers", "integration", "jobs", "mailboxes"].each do |name| task name => "test:prepare" do