This commit is contained in:
r888888888
2014-11-19 17:17:26 -08:00
parent 11731b6dfb
commit 177ef0ebcc
5 changed files with 21 additions and 0 deletions

View File

@@ -48,4 +48,8 @@ class PixivUgoiraService
@content_type = data[:ugoira_content_type]
end
end
def empty?
@frame_data.nil?
end
end

View File

@@ -53,6 +53,10 @@ class Upload < ActiveRecord::Base
unless is_valid_content_type?
raise "invalid content type (only JPEG, PNG, GIF, SWF, and WebM files are allowed)"
end
if is_ugoira? && ugoira_service.empty?
raise "missing frame data for ugoira"
end
end
def validate_md5_confirmation

Binary file not shown.

View File

@@ -32,6 +32,10 @@ module UploadTestMethods
def upload_jpeg(path)
upload_file(path, "image/jpeg", File.basename(path))
end
def upload_zip(path)
upload_file(path, "application/zip", File.basename(path))
end
end
class ActiveSupport::TestCase

View File

@@ -101,6 +101,15 @@ class UploadTest < ActiveSupport::TestCase
end
context "downloader" do
context "for a zip that is not an ugoira" do
should "not validate" do
FileUtils.cp("#{Rails.root}/test/files/invalid_ugoira.zip", "#{Rails.root}/tmp")
@upload = Upload.create(:file => upload_zip("#{Rails.root}/tmp/invalid_ugoira.zip"), :rating => "q", :tag_string => "xxx")
@upload.process!
assert_equal("error: RuntimeError - missing frame data for ugoira", @upload.status)
end
end
context "that is an ugoira" do
setup do
@url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654"