Skip to content

Commit f8e9b14

Browse files
authored
Merge pull request #43 from collectiveidea/fix-missing-port
Fix current url_options without a port (default port)
2 parents a84873a + 8e4b680 commit f8e9b14

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/active_storage/service/db_service_rails70.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def compose(source_keys, destination_key, **)
2020
def current_host
2121
opts = url_options || {}
2222
url = "#{opts[:protocol]}#{opts[:host]}"
23-
url + ":#{opts[:port]}" if opts[:port]
23+
url += ":#{opts[:port]}" if opts[:port]
24+
url
2425
end
2526

2627
def private_url(key, expires_in:, filename:, content_type:, disposition:, **)

spec/service/active_storage/service/db_service_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@
4646
url = service.url('some_key', filename: filename, disposition: :inline, content_type: 'text/plain', expires_in: nil)
4747
expect(url).to match %r{#{host}/active_storage_db/files/}
4848
end
49+
50+
context 'without port' do
51+
let(:url_options) do
52+
{
53+
protocol: 'https://',
54+
host: 'test.example.com',
55+
}
56+
end
57+
58+
it 'returns a public URL' do
59+
filename = ActiveStorage::Filename.new('some_filename')
60+
service = ActiveStorage::Service.configure(:db, config)
61+
url = service.url('some_key', filename: filename, disposition: :inline, content_type: 'text/plain', expires_in: nil)
62+
expect(url).to match %r{https://test.example.com/active_storage_db/files/}
63+
end
64+
end
4965
end
5066

5167
if Rails::VERSION::MAJOR >= 7

0 commit comments

Comments
 (0)