aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_specification/resolver_test.rb
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2013-12-30 11:26:28 -0500
committerschneems <richard.schneeman@gmail.com>2013-12-30 12:21:14 -0500
commit5b96027ef6ac6e507ec9caf9973069345ce6a7cd (patch)
tree6d71bcbc0c3031cc2aa2336024e873b931f1eec1 /activerecord/test/cases/connection_specification/resolver_test.rb
parent16e93561e2695afb6e0f264905e35ffd9381123d (diff)
downloadrails-5b96027ef6ac6e507ec9caf9973069345ce6a7cd.tar.gz
rails-5b96027ef6ac6e507ec9caf9973069345ce6a7cd.tar.bz2
rails-5b96027ef6ac6e507ec9caf9973069345ce6a7cd.zip
Allow "url" sub key in database.yml configuration
Currently a developer can pass in a YAML configuration that fully specifies connection information: ``` production: database: triage_production adapter: password pool: 5 ``` They can also pass in a string that specifies a connection URL directly to an environment key: ``` production: postgresql://localhost/foo ``` This PR allows the use of both a connection url and specifying connection attributes via YAML through the use of the "url" sub key: ``` production: url: postgresql://localhost/foo pool: 3 ``` This will allow developers to inherit Active Record options such as `pool` from `&defaults` and still use a secure connection url such as `<%= ENV['DATABASE_URL'] %>`. The URL is expanded into a hash and then merged back into the YAML hash. If there are any conflicts, the values from the connection URL are preferred. Talked this over with @josevalim
Diffstat (limited to 'activerecord/test/cases/connection_specification/resolver_test.rb')
-rw-r--r--activerecord/test/cases/connection_specification/resolver_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_specification/resolver_test.rb b/activerecord/test/cases/connection_specification/resolver_test.rb
index ba8440a16b..fdd1914cba 100644
--- a/activerecord/test/cases/connection_specification/resolver_test.rb
+++ b/activerecord/test/cases/connection_specification/resolver_test.rb
@@ -31,6 +31,24 @@ module ActiveRecord
"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({