From 5e260574a43d5c2fef8b170138baa9f7e10bfb24 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Thu, 25 Jul 2019 20:08:10 -0400 Subject: Only merge DATABASE_URL settings into the current env This commit fixes a regression where when the `DATABASE_URL` environment variable was set and the current Rails environment had a valid configuration defined in the database config, settings from the environment variable would affect _all_ environments (not just the current one). --- .../merge_and_resolve_default_url_config_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb index 15a045ed23..95e57f42e3 100644 --- a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +++ b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb @@ -347,6 +347,22 @@ module ActiveRecord assert_equal expected, actual end end + + def test_does_not_change_other_environments + ENV["DATABASE_URL"] = "postgres://localhost/foo" + config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" }, "default_env" => {} } + + actual = resolve_spec(:production, config) + assert_equal config["production"].merge("name" => "production"), actual + + actual = resolve_spec(:default_env, config) + assert_equal({ + "host" => "localhost", + "database" => "foo", + "adapter" => "postgresql", + "name" => "default_env" + }, actual) + end end end end -- cgit v1.2.3