From a725c81e1edb14af67adc2eb415907c6c1528bf4 Mon Sep 17 00:00:00 2001 From: Peter Graham Date: Fri, 22 Feb 2013 23:08:31 -0800 Subject: [PATCH] Upload#is_downloadable? returns true for https sources --- app/models/upload.rb | 2 +- test/unit/upload_test.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index 919edcb42..cd2523601 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -247,7 +247,7 @@ class Upload < ActiveRecord::Base module DownloaderMethods # Determines whether the source is downloadable def is_downloadable? - source =~ /^http:\/\// && file_path.blank? + source =~ /^https?:\/\// && file_path.blank? end # Downloads the file to destination_path diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index d4b0a249d..44518811c 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -79,6 +79,23 @@ class UploadTest < ActiveSupport::TestCase end end + context "determining if a file is downloadable" do + should "classify HTTP sources as downloadable" do + @upload = FactoryGirl.create(:source_upload, source: "http://www.example.com/1.jpg") + assert_not_nil(@upload.is_downloadable?) + end + + should "classify HTTPS sources as downloadable" do + @upload = FactoryGirl.create(:source_upload, source: "https://www.example.com/1.jpg") + assert_not_nil(@upload.is_downloadable?) + end + + should "classify non-HTTP/HTTPS sources as not downloadable" do + @upload = FactoryGirl.create(:source_upload, source: "ftp://www.example.com/1.jpg") + assert_nil(@upload.is_downloadable?) + end + end + context "file processor" do should "parse and process a cgi file representation" do FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")