aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorEileen Uchitelle <eileencodes@gmail.com>2019-01-30 09:31:35 -0500
committerEileen Uchitelle <eileencodes@gmail.com>2019-01-30 09:31:35 -0500
commitdedcc1950613b4c756ca7fdc449d0d9315bb39aa (patch)
treeea4ad1130b658aba4a5da971ffa23b420bdfa09e /activerecord/test
parent9bb07b79e4bd855f24c098ba636dae15340e03ed (diff)
downloadrails-dedcc1950613b4c756ca7fdc449d0d9315bb39aa.tar.gz
rails-dedcc1950613b4c756ca7fdc449d0d9315bb39aa.tar.bz2
rails-dedcc1950613b4c756ca7fdc449d0d9315bb39aa.zip
Fix case when we want a UrlConfig but the URL is nil
Previously if the `url` key in a config hash was nil we'd ignore the configuration as invalid. This can happen when you're relying on a `DATABASE_URL` in the env and that is not set in the environment. ``` production: <<: *default url: ENV['DATABASE_URL'] ``` This PR fixes that case by checking if there is a `url` key in the config instead of checking if the `url` is not nil in the config. In addition to changing the conditional we then need to build a url hash to merge with the original hash in the `UrlConfig` object. Fixes #35091
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb8
1 files changed, 8 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 06c1c51724..225cccc62c 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
@@ -46,6 +46,14 @@ module ActiveRecord
assert_equal expected, actual
end
+ def test_resolver_with_nil_database_url_and_current_env
+ ENV["RAILS_ENV"] = "foo"
+ config = { "foo" => { "adapter" => "postgres", "url" => ENV["DATABASE_URL"] } }
+ actual = resolve_spec(:foo, config)
+ expected = { "adapter" => "postgres", "url" => nil, "name" => "foo" }
+ assert_equal expected, actual
+ end
+
def test_resolver_with_database_uri_and_current_env_symbol_key_and_rack_env
ENV["DATABASE_URL"] = "postgres://localhost/foo"
ENV["RACK_ENV"] = "foo"