Skip to content

Commit

Permalink
Fix current url_options without a port (default port)
Browse files Browse the repository at this point in the history
  • Loading branch information
albus522 committed Feb 16, 2024
1 parent 35e5a7e commit 1f5f910
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/active_storage/service/db_service_rails70.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def compose(source_keys, destination_key, **)
def current_host
opts = url_options || {}
url = "#{opts[:protocol]}#{opts[:host]}"
url + ":#{opts[:port]}" if opts[:port]
url += ":#{opts[:port]}" if opts[:port]
url
end

def private_url(key, expires_in:, filename:, content_type:, disposition:, **)
Expand Down
16 changes: 16 additions & 0 deletions spec/service/active_storage/service/db_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@
url = service.url('some_key', filename: filename, disposition: :inline, content_type: 'text/plain', expires_in: nil)
expect(url).to match %r{#{host}/active_storage_db/files/}
end

context 'without port' do
let(:url_options) do
{
protocol: 'https://',
host: 'test.example.com',
}
end

it 'returns a public URL' do
filename = ActiveStorage::Filename.new('some_filename')
service = ActiveStorage::Service.configure(:db, config)
url = service.url('some_key', filename: filename, disposition: :inline, content_type: 'text/plain', expires_in: nil)
expect(url).to match %r{https://test.example.com/active_storage_db/files/}
end
end
end

if Rails::VERSION::MAJOR >= 7
Expand Down

0 comments on commit 1f5f910

Please sign in to comment.