Connection specification now passes the "url" key to the adapter

If the "url" protocol is "jdbc", "http", or "https" the url option will
be passed to the adapter. Previously only urls with the "jdbc" prefix
were passed to the Active Record Adapter, others are assumed to be
adapter specification urls.

Fixes #41137.
This commit is contained in:
Jon Bracy 2021-01-16 11:06:25 -06:00 committed by Rafael Mendonça França
parent 03d3a1b994
commit 29cad39bd5
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
3 changed files with 22 additions and 1 deletions

View File

@ -1,3 +1,12 @@
* Connection specification now passes the "url" key as a configuration for the
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
are assumed to be adapter specification urls.
Fixes #41137.
*Jonathan Bracy*
* Allow to opt-out of `strict_loading` mode on a per-record base.
This is useful when strict loading is enabled application wide or on a

View File

@ -42,7 +42,7 @@ module ActiveRecord
# Return a Hash that can be merged into the main config that represents
# the passed in url
def build_url_hash
if url.nil? || url.start_with?("jdbc:")
if url.nil? || %w(jdbc: http: https:).any? { |protocol| url.start_with?(protocol) }
{ url: url }
else
ConnectionUrlResolver.new(url).to_hash

View File

@ -126,6 +126,18 @@ module ActiveRecord
assert_equal config["production"].symbolize_keys, actual
end
def test_http_url
config = { "production" => { "url" => "http://example.com/path" } }
actual = resolve_config(config, "production")
assert_equal config["production"].symbolize_keys, actual
end
def test_https_url
config = { "production" => { "url" => "https://example.com" } }
actual = resolve_config(config, "production")
assert_equal config["production"].symbolize_keys, actual
end
def test_environment_does_not_exist_in_config_url_does_exist
ENV["DATABASE_URL"] = "postgres://localhost/foo"
config = { "not_default_env" => { "adapter" => "not_postgres", "database" => "not_foo" } }