提交 969a0778 编写于 作者: R Rafael Mendonça França

Merge pull request #13541 from schneems/schneems/db-url-sub-key

Allow "url" sub key in database.yml configuration
* Connection specification now accepts a "url" key. The value of this
key is expected to contain a database URL. The database URL will be
expanded into a hash and merged.
*Richard Schneeman*
* An `ArgumentError` is now raised on a call to `Relation#where.not(nil)`.
Example:
......
......@@ -223,7 +223,15 @@ def resolve_env_connection(spec)
end
end
# Accepts a hash. Expands the "url" key that contains a
# URL database connection to a full connection
# hash and merges with the rest of the hash.
# Connection details inside of the "url" key win any merge conflicts
def resolve_hash_connection(spec)
if url = spec.delete("url")
connection_hash = resolve_string_connection(url)
spec.merge!(connection_hash)
end
spec
end
......
......@@ -31,6 +31,24 @@ def test_url_from_environment
"encoding" => "utf8" }, spec)
end
def test_url_sub_key
spec = resolve :production, 'production' => {"url" => 'abstract://foo?encoding=utf8'}
assert_equal({
"adapter" => "abstract",
"host" => "foo",
"encoding" => "utf8" }, spec)
end
def test_url_sub_key_merges_correctly
hash = {"url" => 'abstract://foo?encoding=utf8&', "adapter" => "sqlite3", "host" => "bar", "pool" => "3"}
spec = resolve :production, 'production' => hash
assert_equal({
"adapter" => "abstract",
"host" => "foo",
"encoding" => "utf8",
"pool" => "3" }, spec)
end
def test_url_host_no_db
spec = resolve 'abstract://foo?encoding=utf8'
assert_equal({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册