mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41144 from malomalo/ar_adapter_config_with_url
AR connection configuration accepts `url` as a key if `adapter` is set
This commit is contained in:
commit
aec71e84d8
3 changed files with 22 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" } }
|
||||
|
|
Loading…
Reference in a new issue