Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/dossier/connection_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def to_hash
password: uri.password,
host: uri.host,
port: uri.port,
database: File.basename(uri.path)
database: database_name
}.merge(params).reject { |k,v| v.nil? }
end

Expand All @@ -32,5 +32,13 @@ def params
Rack::Utils.parse_nested_query(uri.query).symbolize_keys
end

def database_name
path = File.basename(uri.path)
if path.blank? || path == "/"
nil
else
path
end
end
end
end
11 changes: 11 additions & 0 deletions spec/dossier/connection_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@
expect(connection_options.slice(:username, :password, :port)).to be_empty
end

it "drops blank database name" do
database_url = "postgresql://localhost"
connection_options = described_class.new(database_url).to_hash
expect(connection_options.slice(:database)).to be_empty
end

it "drops trailing slash database name" do
database_url = "postgresql://localhost/"
connection_options = described_class.new(database_url).to_hash
expect(connection_options.slice(:database)).to be_empty
end
end