diff options
author | Matthew Draper <matthew@trebex.net> | 2014-04-09 00:17:13 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-04-09 00:17:13 +0930 |
commit | 615e0dcdf1391a8b71ad6556c2e7b9cedf6ffa12 (patch) | |
tree | cb9b650c67b99eac5b15a96c6840e07514f51ff1 /activerecord/test/cases | |
parent | 8f23c220081d0197107490df9aa6e262fac5099e (diff) | |
download | rails-615e0dcdf1391a8b71ad6556c2e7b9cedf6ffa12.tar.gz rails-615e0dcdf1391a8b71ad6556c2e7b9cedf6ffa12.tar.bz2 rails-615e0dcdf1391a8b71ad6556c2e7b9cedf6ffa12.zip |
Less ambition, more deprecation
The "DATABASE_URL_*" idea was moving in the wrong direction.
Instead, let's deprecate the situation where we end up using
ENV['DATABASE_URL'] at all: the Right Way is to explicitly include it in
database.yml with ERB.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handler_test.rb | 70 |
1 files changed, 11 insertions, 59 deletions
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb index d6abc13c0d..a7002bd13d 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -11,14 +11,10 @@ module ActiveRecord def setup @previous_database_url = ENV.delete("DATABASE_URL") - @previous_database_url_default_env = ENV.delete("DATABASE_URL_DEFAULT_ENV") - @previous_database_url_production = ENV.delete("DATABASE_URL_PRODUCTION") end teardown do ENV["DATABASE_URL"] = @previous_database_url - ENV["DATABASE_URL_DEFAULT_ENV"] = @previous_database_url_default_env - ENV["DATABASE_URL_PRODUCTION"] = @previous_database_url_production end def resolve(spec, config) @@ -32,24 +28,7 @@ module ActiveRecord def test_resolver_with_database_uri_and_current_env_symbol_key ENV['DATABASE_URL'] = "postgres://localhost/foo" 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_environment_database_uri_and_current_env_symbol_key - ENV['DATABASE_URL_DEFAULT_ENV'] = "postgres://localhost/foo" - config = { "default_env" => { "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_environment_database_uri_and_global_database_uri_and_current_env_symbol_key - ENV['DATABASE_URL'] = "postgres://localhost/foo" - ENV['DATABASE_URL_DEFAULT_ENV'] = "mysql://host/foo_bar" - config = { "default_env" => { "adapter" => "not_postgres", "database" => "not_foo" } } - actual = resolve(:default_env, config) + actual = assert_deprecated { resolve(:default_env, config) } expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" } assert_equal expected, actual end @@ -65,32 +44,18 @@ module ActiveRecord def test_resolver_with_database_uri_and_known_key ENV['DATABASE_URL'] = "postgres://localhost/foo" config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" } } - actual = resolve(:production, config) + actual = assert_deprecated { resolve(:production, config) } expected = { "adapter"=>"not_postgres", "database"=>"not_foo", "host"=>"localhost" } assert_equal expected, actual end - def test_resolver_with_custom_database_uri_and_no_matching_config - ENV['DATABASE_URL_PRODUCTION'] = "postgres://localhost/foo" - config = {} - actual = resolve(:production, config) - expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" } - assert_equal expected, actual - end - - def test_resolver_with_custom_database_uri_and_custom_key - ENV['DATABASE_URL_PRODUCTION'] = "postgres://localhost/foo" - config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" } } - actual = resolve(:production, config) - expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" } - assert_equal expected, actual - end - 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 - resolve(:production, config) + assert_deprecated do + assert_raises AdapterNotSpecified do + resolve(:production, config) + end end end @@ -107,7 +72,7 @@ module ActiveRecord def test_resolver_with_database_uri_and_supplied_url ENV['DATABASE_URL'] = "not-postgres://not-localhost/not_foo" config = { "production" => { "adapter" => "also_not_postgres", "database" => "also_not_foo" } } - actual = resolve("postgres://localhost/foo", config) + actual = assert_deprecated { resolve("postgres://localhost/foo", config) } expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" } assert_equal expected, actual end @@ -121,24 +86,11 @@ module ActiveRecord 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" } } - actual = klass.new(config).resolve + actual = assert_deprecated { klass.new(config).resolve } expect_prod = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" } assert_equal expect_prod, actual["default_env"] end - def test_environment_key_available_immediately - ENV['DATABASE_URL_PRODUCTION'] = "postgres://localhost/foo" - config = {} - actual = klass.new(config).resolve - expected = { "production" => - { "adapter" => "postgresql", - "database" => "foo", - "host" => "localhost" - } - } - assert_equal expected, actual - end - def test_string_connection config = { "default_env" => "postgres://localhost/foo" } actual = klass.new(config).resolve @@ -179,7 +131,7 @@ module ActiveRecord ENV['DATABASE_URL'] = "postgres://localhost/foo" config = {} - actual = klass.new(config).resolve + actual = assert_deprecated { klass.new(config).resolve } expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" } @@ -210,7 +162,7 @@ module ActiveRecord ENV['DATABASE_URL'] = "postgres://localhost/foo" config = {"default_env" => { "pool" => "5" } } - actual = klass.new(config).resolve + actual = assert_deprecated { klass.new(config).resolve } expected = { "default_env" => { "adapter" => "postgresql", "database" => "foo", @@ -225,7 +177,7 @@ module ActiveRecord ENV['DATABASE_URL'] = "postgres://localhost/foo" config = {"default_env" => { "adapter" => "NOT-POSTGRES", "database" => "NOT-FOO", "pool" => "5" } } - actual = klass.new(config).resolve + actual = assert_deprecated { klass.new(config).resolve } expected = { "default_env" => { "adapter" => "postgresql", "database" => "foo", |