From 396dba08741b2c1d5a41debbb4bbde799c9f2a31 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Tue, 23 Jul 2019 15:55:48 -0400 Subject: Fix multiple database support for DATABASE_URL env variable This commit fixes an issue where multi-database configurations were incompatible with setting a `DATABASE_URL` environment variable. As part of this work, this commit also includes a light refactor to make both multi and single database configurations lead into the same code path so they behave the same. As mentioned in #36736, this regression was introduced as part of f2ad69fe7a605b01bb7c37eeac6a9b4e7deb488e --- .../merge_and_resolve_default_url_config_test.rb | 24 ++++++++++++++++++++++ 1 file changed, 24 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 6372abbf3f..15a045ed23 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 @@ -323,6 +323,30 @@ module ActiveRecord assert_equal expected, actual end + + def test_tiered_configs_with_database_url + ENV["DATABASE_URL"] = "postgres://localhost/foo" + + config = { + "default_env" => { + "primary" => { "pool" => 5 }, + "animals" => { "pool" => 5 } + } + } + + expected = { + "adapter" => "postgresql", + "database" => "foo", + "host" => "localhost", + "pool" => 5 + } + + ["primary", "animals"].each do |spec_name| + configs = ActiveRecord::DatabaseConfigurations.new(config) + actual = configs.configs_for(env_name: "default_env", spec_name: spec_name).config + assert_equal expected, actual + end + end end end end -- cgit v1.2.3