Skip to content

Commit

Permalink
#url_options_supported? breaks when #file is nil
Browse files Browse the repository at this point in the history
Closes #2361, Refs. #2332
  • Loading branch information
mshibuya committed Dec 25, 2018
1 parent 930abb7 commit 0b9a64a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def read_source_file(file_body)
end

def url_options_supported?(local_file)
parameters = file.method(:url).parameters
parameters = local_file.method(:url).parameters
parameters.count == 2 && parameters[1].include?(:options)
end
end
Expand Down
27 changes: 22 additions & 5 deletions spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def fog_tests(fog_credentials)
shared_examples_for "#{fog_credentials[:provider]} storage" do

before do
WebMock.disable! unless Fog.mocking?
CarrierWave.configure do |config|
config.reset_config
config.fog_provider = "fog/#{fog_credentials[:provider].downcase}"
Expand Down Expand Up @@ -34,6 +35,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
CarrierWave.configure do |config|
config.reset_config
end
WebMock.enable! unless Fog.mocking?
end

describe '#cache_stored_file!' do
Expand Down Expand Up @@ -343,7 +345,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
end

describe '#clean_cache!' do
let(:today) { '2016/10/09 10:00:00'.to_time }
let(:today) { Time.now.round }
let(:five_days_ago) { today.ago(5.days) }
let(:three_days_ago) { today.ago(3.days) }
let(:yesterday) { today.yesterday }
Expand Down Expand Up @@ -431,7 +433,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base

it "should not be available at public URL" do
unless Fog.mocking? || fog_credentials[:provider] == 'Local'
expect(running{ open(@fog_file.public_url) }).to raise_error
expect(running{ open(@fog_file.public_url) }).to raise_error OpenURI::HTTPError
end
end

Expand All @@ -446,9 +448,24 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
end

it "should handle query params" do
if ['AWS', 'Google'].include?(@provider) && !Fog.mocking?
headers = Excon.get(@fog_file.url(:query => {"response-content-disposition" => "attachment"})).headers
expect(headers["Content-Disposition"]).to eq("attachment")
if ['AWS', 'Google'].include?(@provider)
url = @fog_file.url(:query => {"response-content-disposition" => "attachment"})
expect(url).to match(/response-content-disposition=attachment/)
unless Fog.mocking?
# Workaround for S3 SignatureDoesNotMatch issue
# https://github.com/excon/excon/issues/475
Excon.defaults[:omit_default_port] = true
response = Excon.get(url)
expect(response.status).to be 200
expect(response.headers["Content-Disposition"]).to eq("attachment")
end
end
end

it "should not use #file to get signed url" do
if ['AWS', 'Google'].include?(@provider)
allow(@fog_file).to receive(:file).and_return(nil)
expect { @fog_file.url }.not_to raise_error
end
end
end
Expand Down

0 comments on commit 0b9a64a

Please sign in to comment.