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")