diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index bdfad6fd68..ef1d07f1c3 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -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 diff --git a/activerecord/lib/active_record/database_configurations/url_config.rb b/activerecord/lib/active_record/database_configurations/url_config.rb index f4ad016d38..a8ee4f64fc 100644 --- a/activerecord/lib/active_record/database_configurations/url_config.rb +++ b/activerecord/lib/active_record/database_configurations/url_config.rb @@ -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 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 d85eb88eec..9a117e4c56 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 @@ -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" } }