Skip to content

Commit

Permalink
Merge pull request rails#53628 from fatkodima/fix-database_url-only-d…
Browse files Browse the repository at this point in the history
…atabase

Restore back the ability to pass only database name for `DATABASE_URL`
  • Loading branch information
byroot committed Nov 13, 2024
1 parent 876494e commit 24fde60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def raw_config

def resolved_adapter
adapter = uri.scheme && @uri.scheme.tr("-", "_")
adapter = ActiveRecord.protocol_adapters[adapter] || adapter
if adapter && ActiveRecord.protocol_adapters[adapter]
adapter = ActiveRecord.protocol_adapters[adapter]
end
adapter
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ def test_resolver_with_database_uri_and_supplied_url
assert_equal expected, actual.configuration_hash
end

def test_resolver_with_database_uri_containing_only_database_name
ENV["DATABASE_URL"] = "foo"
ENV["RAILS_ENV"] = "test"

config = { "test" => { "adapter" => "postgres", "database" => "not_foo", "host" => "localhost" } }
actual = resolve_db_config(:test, config)
expected = { adapter: "postgres", database: "foo", host: "localhost" }

assert_equal expected, actual.configuration_hash
end

def test_jdbc_url
config = { "production" => { "adapter" => "abstract", "url" => "jdbc:postgres://localhost/foo" } }
actual = resolve_config(config, "production")
Expand Down

0 comments on commit 24fde60

Please sign in to comment.