Upload#is_downloadable? returns true for https sources

This commit is contained in:
Peter Graham
2013-02-22 23:08:31 -08:00
parent 4330e85b17
commit a725c81e1e
2 changed files with 18 additions and 1 deletions

View File

@@ -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

View File

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