From 0b9a64a1bb9f20d1de154dc3bf2e2dd988210220 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Tue, 25 Dec 2018 20:29:49 +0900 Subject: [PATCH] #url_options_supported? breaks when #file is nil Closes #2361, Refs. #2332 --- lib/carrierwave/storage/fog.rb | 2 +- spec/storage/fog_helper.rb | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/carrierwave/storage/fog.rb b/lib/carrierwave/storage/fog.rb index 14c416aad..863e6a130 100644 --- a/lib/carrierwave/storage/fog.rb +++ b/lib/carrierwave/storage/fog.rb @@ -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 diff --git a/spec/storage/fog_helper.rb b/spec/storage/fog_helper.rb index fb898cbb0..f1d6da7cf 100644 --- a/spec/storage/fog_helper.rb +++ b/spec/storage/fog_helper.rb @@ -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}" @@ -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 @@ -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 } @@ -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 @@ -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