aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJohn Crepezzi <seejohnrun@github.com>2019-07-23 15:55:48 -0400
committerJohn Crepezzi <seejohnrun@github.com>2019-07-24 16:31:24 -0400
commit396dba08741b2c1d5a41debbb4bbde799c9f2a31 (patch)
treea7e29cc3e0dfc322347f29678530e47ec2d1e708 /activerecord/test
parent9c913116c634fe5fe2159a94b8f1a244801a4877 (diff)
downloadrails-396dba08741b2c1d5a41debbb4bbde799c9f2a31.tar.gz
rails-396dba08741b2c1d5a41debbb4bbde799c9f2a31.tar.bz2
rails-396dba08741b2c1d5a41debbb4bbde799c9f2a31.zip
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
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb24
1 files changed, 24 insertions, 0 deletions
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