Methods
R
S
T
Instance Public methods
resolve_config(config)
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 18
def resolve_config(config)
  ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig.new(config).resolve
end
resolve_spec(spec, config)
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 22
def resolve_spec(spec, config)
  ConnectionSpecification::Resolver.new(resolve_config(config)).resolve(spec)
end
setup()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 6
def setup
  @previous_database_url = ENV.delete("DATABASE_URL")
  @previous_rack_env = ENV.delete("RACK_ENV")
  @previous_rails_env = ENV.delete("RAILS_ENV")
end
test_blank()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 168
def test_blank
  config = {}
  actual = resolve_config(config)
  assert_equal config, actual
end
test_blank_with_database_url()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 174
def test_blank_with_database_url
  ENV['DATABASE_URL'] = "postgres://localhost/foo"

  config   = {}
  actual   = resolve_config(config)
  expected = { "adapter"  => "postgresql",
               "database" => "foo",
               "host"     => "localhost" }
  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[:default_env]
  assert_equal nil,      actual[:production]
  assert_equal nil,      actual[:development]
  assert_equal nil,      actual[:test]
end
test_blank_with_database_url_with_rack_env()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 214
def test_blank_with_database_url_with_rack_env
  ENV['RACK_ENV'] = "not_production"
  ENV['DATABASE_URL'] = "postgres://localhost/foo"

  config   = {}
  actual   = resolve_config(config)
  expected = { "adapter"  => "postgresql",
               "database" => "foo",
               "host"     => "localhost" }

  assert_equal expected, actual["not_production"]
  assert_equal nil,      actual["production"]
  assert_equal nil,      actual["default_env"]
  assert_equal nil,      actual["development"]
  assert_equal nil,      actual["test"]
  assert_equal nil,      actual[:default_env]
  assert_equal nil,      actual[:not_production]
  assert_equal nil,      actual[:production]
  assert_equal nil,      actual[:development]
  assert_equal nil,      actual[:test]
end
test_blank_with_database_url_with_rails_env()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 192
def test_blank_with_database_url_with_rails_env
  ENV['RAILS_ENV'] = "not_production"
  ENV['DATABASE_URL'] = "postgres://localhost/foo"

  config   = {}
  actual   = resolve_config(config)
  expected = { "adapter"  => "postgresql",
               "database" => "foo",
               "host"     => "localhost" }

  assert_equal expected, actual["not_production"]
  assert_equal nil,      actual["production"]
  assert_equal nil,      actual["default_env"]
  assert_equal nil,      actual["development"]
  assert_equal nil,      actual["test"]
  assert_equal nil,      actual[:default_env]
  assert_equal nil,      actual[:not_production]
  assert_equal nil,      actual[:production]
  assert_equal nil,      actual[:development]
  assert_equal nil,      actual[:test]
end
test_database_url_with_ipv6_host_and_port()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 236
def test_database_url_with_ipv6_host_and_port
  ENV['DATABASE_URL'] = "postgres://[::1]:5454/foo"

  config   = {}
  actual   = resolve_config(config)
  expected = { "adapter"  => "postgresql",
               "database" => "foo",
               "host"     => "::1",
               "port"     => 5454 }
  assert_equal expected, actual["default_env"]
end
test_environment_does_not_exist_in_config_url_does_exist()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 122
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      = resolve_config(config)
  expect_prod = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
  assert_equal expect_prod, actual["default_env"]
end
test_hash()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 162
def test_hash
  config = { "production" => { "adapter" => "postgres", "database" => "foo" } }
  actual = resolve_config(config)
  assert_equal config, actual
end
test_jdbc_url()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 116
def test_jdbc_url
  config   = { "production" => { "url" => "jdbc:postgres://localhost/foo" } }
  actual   = resolve_config(config)
  assert_equal config, actual
end
test_merge_conflicts_with_database_url()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 277
def test_merge_conflicts_with_database_url
  ENV['DATABASE_URL'] = "postgres://localhost/foo"

  config   = {"default_env" => { "adapter" => "NOT-POSTGRES", "database" => "NOT-FOO", "pool" => "5" } }
  actual   = resolve_config(config)
  expected = { "default_env" =>
               { "adapter"  => "postgresql",
                 "database" => "foo",
                 "host"     => "localhost",
                 "pool"     => "5"
                }
              }
  assert_equal expected, actual
end
test_merge_no_conflicts_with_database_url()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 262
def test_merge_no_conflicts_with_database_url
  ENV['DATABASE_URL'] = "postgres://localhost/foo"

  config   = {"default_env" => { "pool" => "5" } }
  actual   = resolve_config(config)
  expected = { "default_env" =>
               { "adapter"  => "postgresql",
                 "database" => "foo",
                 "host"     => "localhost",
                 "pool"     => "5"
                }
              }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_and_current_env_string_key()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 54
def test_resolver_with_database_uri_and_and_current_env_string_key
  ENV['DATABASE_URL'] = "postgres://localhost/foo"
  config   = { "default_env" => {  "adapter" => "not_postgres", "database" => "not_foo" } }
  actual   = assert_deprecated { resolve_spec("default_env", config) }
  expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_and_current_env_string_key_and_rack_env()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 72
def test_resolver_with_database_uri_and_and_current_env_string_key_and_rack_env
  ENV['DATABASE_URL'] = "postgres://localhost/foo"
  ENV['RACK_ENV'] = "foo"

  config   = { "not_production" => {"adapter" => "not_postgres", "database" => "not_foo" } }
  actual   = assert_deprecated { resolve_spec("foo", config) }
  expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_and_current_env_string_key_and_rails_env()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 62
def test_resolver_with_database_uri_and_and_current_env_string_key_and_rails_env
  ENV['DATABASE_URL'] = "postgres://localhost/foo"
  ENV['RAILS_ENV'] = "foo"

  config   = { "not_production" => {"adapter" => "not_postgres", "database" => "not_foo" } }
  actual   = assert_deprecated { resolve_spec("foo", config) }
  expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_current_env_symbol_key()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 26
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_spec(:default_env, config)
  expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_current_env_symbol_key_and_rack_env()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 44
def test_resolver_with_database_uri_and_current_env_symbol_key_and_rack_env
  ENV['DATABASE_URL'] = "postgres://localhost/foo"
  ENV['RACK_ENV']     = "foo"

  config   = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
  actual   = resolve_spec(:foo, config)
  expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_current_env_symbol_key_and_rails_env()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 34
def test_resolver_with_database_uri_and_current_env_symbol_key_and_rails_env
  ENV['DATABASE_URL'] = "postgres://localhost/foo"
  ENV['RAILS_ENV']    = "foo"

  config   = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
  actual   = resolve_spec(:foo, config)
  expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_known_key()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 82
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_spec(:production, config)
  expected = { "adapter"=>"not_postgres", "database"=>"not_foo", "host"=>"localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_supplied_url()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 108
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_spec("postgres://localhost/foo", config)
  expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
  assert_equal expected, actual
end
test_resolver_with_database_uri_and_unknown_string_key()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 98
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
     resolve_spec("production", config)
    end
  end
end
test_resolver_with_database_uri_and_unknown_symbol_key()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 90
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_spec(:production, config)
  end
end
test_string_connection()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 138
def test_string_connection
  config   = { "default_env" => "postgres://localhost/foo" }
  actual   = resolve_config(config)
  expected = { "default_env" =>
               { "adapter"  => "postgresql",
                 "database" => "foo",
                 "host"     => "localhost"
                }
              }
  assert_equal expected, actual
end
test_url_sub_key()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 150
def test_url_sub_key
  config   = { "default_env" => { "url" => "postgres://localhost/foo" } }
  actual   = resolve_config(config)
  expected = { "default_env" =>
               { "adapter"  => "postgresql",
                 "database" => "foo",
                 "host"     => "localhost"
                }
              }
  assert_equal expected, actual
end
test_url_sub_key_with_database_url()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 248
def test_url_sub_key_with_database_url
  ENV['DATABASE_URL'] = "NOT-POSTGRES://localhost/NOT_FOO"

  config   = { "default_env" => { "url" => "postgres://localhost/foo" } }
  actual   = resolve_config(config)
  expected = { "default_env" =>
              { "adapter"  => "postgresql",
                 "database" => "foo",
                 "host"     => "localhost"
                }
              }
  assert_equal expected, actual
end
test_url_with_hyphenated_scheme()
# File activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb, line 130
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_spec(:default_env, config)
  expected = { "adapter"=>"ibm_db", "database"=>"foo", "host"=>"localhost" }
  assert_equal expected, actual
end