aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2019-06-27 12:56:30 -0400
committereileencodes <eileencodes@gmail.com>2019-06-27 13:07:23 -0400
commitf2ad69fe7a605b01bb7c37eeac6a9b4e7deb488e (patch)
treedf799c7e327a35f83da0e86a3ce4ee380cb0ee90 /activerecord/lib
parent40246125b99ed1f7d7ea869980523e50a0ec9a96 (diff)
downloadrails-f2ad69fe7a605b01bb7c37eeac6a9b4e7deb488e.tar.gz
rails-f2ad69fe7a605b01bb7c37eeac6a9b4e7deb488e.tar.bz2
rails-f2ad69fe7a605b01bb7c37eeac6a9b4e7deb488e.zip
Fix broken url configs
This PR is to fix #36559 but I also found other issues that haven't been reported. The check for `(config.size == 1 && config.values.all? { |v| v.is_a? String })` was naive. The only reason this passed was because we had tests that had single hash size configs, but that doesn't mean we don't want to create a hash config in other cases. So this now checks for `config["database"] || config["adapter"] || ENV["DATABASE_URL"]`. In the end for url configs we still get a UrlConfig but we need to pass through the HashConfig to create the right kind of UrlConfig. The UrlConfig's are really complex and I don't necessarily understand everything that's needed in order to act the same as Rails 5.2. I edited the connection handler test to demonstrate how the previous implementation was broken when checking config size. Now old and new tests pass so I think this is closer to 5.2. Fixes #36559
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/database_configurations.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/database_configurations.rb b/activerecord/lib/active_record/database_configurations.rb
index 44b5cfc738..b917f4e6b7 100644
--- a/activerecord/lib/active_record/database_configurations.rb
+++ b/activerecord/lib/active_record/database_configurations.rb
@@ -141,7 +141,7 @@ module ActiveRecord
config_without_url.delete "url"
ActiveRecord::DatabaseConfigurations::UrlConfig.new(env_name, spec_name, url, config_without_url)
- elsif config["database"] || (config.size == 1 && config.values.all? { |v| v.is_a? String })
+ elsif config["database"] || config["adapter"] || ENV["DATABASE_URL"]
ActiveRecord::DatabaseConfigurations::HashConfig.new(env_name, spec_name, config)
else
config.each_pair.map do |sub_spec_name, sub_config|