aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_adapters/connection_handler_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-09 11:03:10 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-09 11:03:10 -0700
commitdb5e578b647e1730ea2aecb1ca58fd9a434f6cf6 (patch)
tree524517ae1ffc1ec01af367d72a51a8323dee931b /activerecord/test/cases/connection_adapters/connection_handler_test.rb
parent3321d1a2d1908f25d962169d0a88b55bca3c2370 (diff)
parent7b75b678cf11a1aed7927a9db42fb60a38726450 (diff)
downloadrails-db5e578b647e1730ea2aecb1ca58fd9a434f6cf6.tar.gz
rails-db5e578b647e1730ea2aecb1ca58fd9a434f6cf6.tar.bz2
rails-db5e578b647e1730ea2aecb1ca58fd9a434f6cf6.zip
Merge branch 'master' into adequaterecord
* master: (26 commits) Avoid URI parsing Add missing require so requiring `active_support/cache` works again. depend_on_asset is not required anymore on sprockets-rails 2.1.2 upgrading section for 4.1 is no longer WIP. [ci skip] Expand explanation of how to set secrets.yml. [ci skip] Guides: minor typo fixed [ci skip] Fixed problem where `1.day.eql?(1.day)` is false new CHANGELOGs entries are in the top [ci skip] Updates the maintenance policy with new Rails versions Dont abbreviate that which needs no abbreviation Dont encourage aliases now that we have variants Use short-form for the scaffold render calls and drop the needless test Drop in @jeremy's new database.yml template text Don't deprecate after all Less ambition, more deprecation Ensure we correctly and immediately load all ENV entries Give a deprecation message even when the lookup fails Rearrange the config merger some more entry is always a Hash Check env_url only once ... Conflicts: Gemfile
Diffstat (limited to 'activerecord/test/cases/connection_adapters/connection_handler_test.rb')
-rw-r--r--activerecord/test/cases/connection_adapters/connection_handler_test.rb71
1 files changed, 45 insertions, 26 deletions
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
index e097449029..f2d18e812d 100644
--- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb
+++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
@@ -25,35 +25,45 @@ module ActiveRecord
ConnectionSpecification::Resolver.new(klass.new(config).resolve).spec(spec)
end
- def test_resolver_with_database_uri_and_known_key
+ def test_resolver_with_database_uri_and_current_env_symbol_key
ENV['DATABASE_URL'] = "postgres://localhost/foo"
- config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
- actual = resolve(:production, config)
+ config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
+ actual = resolve(:default_env, config)
expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
assert_equal expected, actual
end
- def test_resolver_with_database_uri_and_known_string_key
+ def test_resolver_with_database_uri_and_and_current_env_string_key
ENV['DATABASE_URL'] = "postgres://localhost/foo"
- config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
- actual = assert_deprecated { resolve("production", config) }
+ config = { "default_env" => { "adapter" => "not_postgres", "database" => "not_foo" } }
+ actual = assert_deprecated { resolve("default_env", config) }
expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
assert_equal expected, actual
end
- def test_resolver_with_database_uri_and_unknown_symbol_key
+ def test_resolver_with_database_uri_and_known_key
ENV['DATABASE_URL'] = "postgres://localhost/foo"
- config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
+ config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" } }
actual = resolve(:production, config)
- expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
+ expected = { "adapter"=>"not_postgres", "database"=>"not_foo", "host"=>"localhost" }
assert_equal expected, actual
end
- def test_resolver_with_database_uri_and_unknown_string_key
+ def test_resolver_with_database_uri_and_unknown_symbol_key
ENV['DATABASE_URL'] = "postgres://localhost/foo"
config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
assert_raises AdapterNotSpecified do
- spec("production", config)
+ resolve(:production, config)
+ end
+ end
+
+ def test_resolver_with_database_uri_and_unknown_string_key
+ ENV['DATABASE_URL'] = "postgres://localhost/foo"
+ config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
+ assert_deprecated do
+ assert_raises AdapterNotSpecified do
+ spec("production", config)
+ end
end
end
@@ -73,16 +83,24 @@ module ActiveRecord
def test_environment_does_not_exist_in_config_url_does_exist
ENV['DATABASE_URL'] = "postgres://localhost/foo"
- config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
+ config = { "not_default_env" => { "adapter" => "not_postgres", "database" => "not_foo" } }
actual = klass.new(config).resolve
expect_prod = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
- assert_equal expect_prod, actual["production"]
+ assert_equal expect_prod, actual["default_env"]
+ end
+
+ def test_url_with_hyphenated_scheme
+ ENV['DATABASE_URL'] = "ibm-db://localhost/foo"
+ config = { "default_env" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" } }
+ actual = resolve(:default_env, config)
+ expected = { "adapter"=>"ibm_db", "database"=>"foo", "host"=>"localhost" }
+ assert_equal expected, actual
end
def test_string_connection
- config = { "production" => "postgres://localhost/foo" }
+ config = { "default_env" => "postgres://localhost/foo" }
actual = klass.new(config).resolve
- expected = { "production" =>
+ expected = { "default_env" =>
{ "adapter" => "postgresql",
"database" => "foo",
"host" => "localhost"
@@ -92,9 +110,9 @@ module ActiveRecord
end
def test_url_sub_key
- config = { "production" => { "url" => "postgres://localhost/foo" } }
+ config = { "default_env" => { "url" => "postgres://localhost/foo" } }
actual = klass.new(config).resolve
- expected = { "production" =>
+ expected = { "default_env" =>
{ "adapter" => "postgresql",
"database" => "foo",
"host" => "localhost"
@@ -123,9 +141,10 @@ module ActiveRecord
expected = { "adapter" => "postgresql",
"database" => "foo",
"host" => "localhost" }
- assert_equal expected, actual["production"]
- assert_equal expected, actual["development"]
- assert_equal expected, actual["test"]
+ assert_equal expected, actual["default_env"]
+ assert_equal nil, actual["production"]
+ assert_equal nil, actual["development"]
+ assert_equal nil, actual["test"]
assert_equal nil, actual[:production]
assert_equal nil, actual[:development]
assert_equal nil, actual[:test]
@@ -134,9 +153,9 @@ module ActiveRecord
def test_url_sub_key_with_database_url
ENV['DATABASE_URL'] = "NOT-POSTGRES://localhost/NOT_FOO"
- config = { "production" => { "url" => "postgres://localhost/foo" } }
+ config = { "default_env" => { "url" => "postgres://localhost/foo" } }
actual = klass.new(config).resolve
- expected = { "production" =>
+ expected = { "default_env" =>
{ "adapter" => "postgresql",
"database" => "foo",
"host" => "localhost"
@@ -148,9 +167,9 @@ module ActiveRecord
def test_merge_no_conflicts_with_database_url
ENV['DATABASE_URL'] = "postgres://localhost/foo"
- config = {"production" => { "pool" => "5" } }
+ config = {"default_env" => { "pool" => "5" } }
actual = klass.new(config).resolve
- expected = { "production" =>
+ expected = { "default_env" =>
{ "adapter" => "postgresql",
"database" => "foo",
"host" => "localhost",
@@ -163,9 +182,9 @@ module ActiveRecord
def test_merge_conflicts_with_database_url
ENV['DATABASE_URL'] = "postgres://localhost/foo"
- config = {"production" => { "adapter" => "NOT-POSTGRES", "database" => "NOT-FOO", "pool" => "5" } }
+ config = {"default_env" => { "adapter" => "NOT-POSTGRES", "database" => "NOT-FOO", "pool" => "5" } }
actual = klass.new(config).resolve
- expected = { "production" =>
+ expected = { "default_env" =>
{ "adapter" => "postgresql",
"database" => "foo",
"host" => "localhost",