mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36565 from rails/fix-url-configs
Fix broken url configs
This commit is contained in:
commit
04d2fda1f8
3 changed files with 33 additions and 2 deletions
|
@ -141,7 +141,7 @@ module ActiveRecord
|
|||
config_without_url.delete "url"
|
||||
|
||||
ActiveRecord::DatabaseConfigurations::UrlConfig.new(env_name, spec_name, url, config_without_url)
|
||||
elsif config["database"] || (config.size == 1 && config.values.all? { |v| v.is_a? String })
|
||||
elsif config["database"] || config["adapter"] || ENV["DATABASE_URL"]
|
||||
ActiveRecord::DatabaseConfigurations::HashConfig.new(env_name, spec_name, config)
|
||||
else
|
||||
config.each_pair.map do |sub_spec_name, sub_config|
|
||||
|
|
|
@ -29,7 +29,7 @@ module ActiveRecord
|
|||
|
||||
def test_establish_connection_uses_spec_name
|
||||
old_config = ActiveRecord::Base.configurations
|
||||
config = { "readonly" => { "adapter" => "sqlite3" } }
|
||||
config = { "readonly" => { "adapter" => "sqlite3", "pool" => "5" } }
|
||||
ActiveRecord::Base.configurations = config
|
||||
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(ActiveRecord::Base.configurations)
|
||||
spec = resolver.spec(:readonly)
|
||||
|
|
|
@ -273,6 +273,37 @@ module ActiveRecord
|
|||
}
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
def test_merge_no_conflicts_with_database_url_and_adapter
|
||||
ENV["DATABASE_URL"] = "postgres://localhost/foo"
|
||||
|
||||
config = { "default_env" => { "adapter" => "postgresql", "pool" => "5" } }
|
||||
actual = resolve_config(config)
|
||||
expected = { "default_env" =>
|
||||
{ "adapter" => "postgresql",
|
||||
"database" => "foo",
|
||||
"host" => "localhost",
|
||||
"pool" => "5"
|
||||
}
|
||||
}
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
def test_merge_no_conflicts_with_database_url_and_numeric_pool
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue