added resizer
This commit is contained in:
@@ -9,4 +9,20 @@ require 'rails/test_help'
|
||||
Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file}
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
protected
|
||||
def upload_file(path, content_type, filename)
|
||||
tempfile = Tempfile.new(filename)
|
||||
FileUtils.copy_file(path, tempfile.path)
|
||||
(class << tempfile; self; end).class_eval do
|
||||
alias local_path path
|
||||
define_method(:original_filename) {filename}
|
||||
define_method(:content_type) {content_type}
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
def upload_jpeg(path)
|
||||
upload_file(path, "image/jpeg", File.basename(path))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,41 @@
|
||||
require 'test_helper'
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "A post download" do
|
||||
setup do
|
||||
@source = "http://www.google.com/intl/en_ALL/images/logo.gif"
|
||||
@tempfile = Tempfile.new("danbooru-test")
|
||||
@download = ::Post::Pending::Download.new(@source, @tempfile.path)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@tempfile.close
|
||||
end
|
||||
|
||||
should "stream a file from an HTTP source" do
|
||||
@download.http_get_streaming(@download.source) do |resp|
|
||||
assert_equal("200", resp.code)
|
||||
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
|
||||
end
|
||||
end
|
||||
|
||||
should "throw an exception when the file is larger than the maximum" do
|
||||
assert_raise(Post::Pending::Download::Error) do
|
||||
@download.http_get_streaming(@download.source, :max_size => 1) do |resp|
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "store the file in the tempfile path" do
|
||||
@download.download!
|
||||
assert_equal(@source, @download.source)
|
||||
assert(File.exists?(@tempfile.path), "temp file should exist")
|
||||
assert(File.size(@tempfile.path) > 0, "should have data")
|
||||
end
|
||||
|
||||
should "initialize the content type" do
|
||||
@download.download!
|
||||
assert_match(/text\/html/, @download.content_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user