Skip to content

Instantly share code, notes, and snippets.

@trevorturk
Created February 13, 2011 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorturk/824561 to your computer and use it in GitHub Desktop.
Save trevorturk/824561 to your computer and use it in GitHub Desktop.
diff --git i/lib/carrierwave/uploader/download.rb w/lib/carrierwave/uploader/download.rb
index 123168b..5f39eae 100644
--- i/lib/carrierwave/uploader/download.rb
+++ w/lib/carrierwave/uploader/download.rb
@@ -13,7 +13,7 @@ module CarrierWave
class RemoteFile
def initialize(uri)
- @uri = URI.parse(URI.escape(uri))
+ @uri = uri
end
def original_filename
@@ -52,12 +52,24 @@ module CarrierWave
#
def download!(uri)
unless uri.blank?
- file = RemoteFile.new(uri)
+ processed_uri = process_uri(uri)
+ file = RemoteFile.new(processed_uri)
raise CarrierWave::DownloadError, "trying to download a file which is not served over HTTP" unless file.http?
cache!(file)
end
end
+ ##
+ # Processes the given URL by parsing and escaping it. Public to allow overriding.
+ #
+ # === Parameters
+ #
+ # [url (String)] The URL where the remote file is stored
+ #
+ def process_uri(uri)
+ URI.parse(URI.escape(uri))
+ end
+
end # Download
end # Uploader
end # CarrierWave
diff --git i/spec/uploader/download_spec.rb w/spec/uploader/download_spec.rb
index 312451a..e271d2f 100644
--- i/spec/uploader/download_spec.rb
+++ w/spec/uploader/download_spec.rb
@@ -73,6 +73,22 @@ describe CarrierWave::Uploader::Download do
@uploader.url.should == '/uploads/tmp/20071201-1234-345-2255/file.png'
end
end
+
+ describe '#download! with an overridden process_uri method' do
-end
+ before do
+ @uploader_class.class_eval do
+ def process_uri(uri)
+ raise CarrierWave::DownloadError
+ end
+ end
+ end
+
+ it "should allow overriding the process_uri method" do
+ running {
+ @uploader.download!('http://www.example.com/test/file.png')
+ }.should raise_error(CarrierWave::DownloadError)
+ end
+ end
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment