Skip to content

Commit

Permalink
Merge pull request #43 from collectiveidea/fix-missing-port
Browse files Browse the repository at this point in the history
Fix current url_options without a port (default port)
  • Loading branch information
blocknotes authored Sep 7, 2024
2 parents a84873a + 8e4b680 commit f8e9b14
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 f8e9b14

Please sign in to comment.