Commit 726f183c by Jon Yurek

WIP

parent fb13e2ec
......@@ -32,6 +32,7 @@ end
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
$previous_count = 0
class Test::Unit::TestCase
def setup
silence_warnings do
......@@ -42,8 +43,21 @@ class Test::Unit::TestCase
end
end
def teardown
report_files
end
def report_files
ObjectSpace.each_object(IO){|io| puts "Open IO: #{io.inspect}" unless io.closed? }
files = []
ObjectSpace.each_object(IO){|io| files << io unless io.closed? }
if files.count > $previous_count
puts __name__
puts "#{files.count} files"
files.each do |file|
puts "Open IO: #{file.inspect}"
end
end
$previous_count = files.count
end
end
......
require './test/helper'
# class File
# def initialize_with_logging(*args)
# p "NEW FILE #{args.inspect}"
# p caller
# initialize_without_logging(*args)
# end
# alias_method :initialize_without_logging, :initialize
# alias_method :initialize, :initialize_with_logging
# end
# class Tempfile
# def initialize_with_logging(*args)
# p "NEW #{args.inspect}"
# initialize_without_logging(*args)
# end
# alias_method :initialize_without_logging, :initialize
# alias_method :initialize, :initialize_with_logging
# end
class AttachmentAdapterTest < Test::Unit::TestCase
def setup
......@@ -7,10 +25,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
@attachment = Dummy.new.avatar
end
def teardown
report_files
end
context "for an attachment" do
setup do
@file = File.new(fixture_file("5k.png"))
......@@ -22,7 +36,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
teardown do
@subject.close
@file.close
end
......@@ -63,8 +76,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
context "for a file with restricted characters in the name" do
setup do
file_contents = File.new(fixture_file("animated.gif"))
@file = StringIO.new(file_contents.read)
file_contents = IO.read(fixture_file("animated.gif"))
@file = StringIO.new(file_contents)
@file.stubs(:original_filename).returns('image:restricted.gif')
@file.binmode
......@@ -74,7 +87,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
teardown do
@file.close
@subject.close
end
should "not generate paths that include restricted characters" do
......
require './test/helper'
class File
def initialize_with_logging(*args)
p "NEW FILE #{args.inspect}"
p caller
initialize_without_logging(*args)
end
alias_method :initialize_without_logging, :initialize
alias_method :initialize, :initialize_with_logging
end
# class Tempfile
# def initialize_with_logging(*args)
# p "NEW #{args.inspect}"
# initialize_without_logging(*args)
# end
# alias_method :initialize_without_logging, :initialize
# alias_method :initialize, :initialize_with_logging
# end
class FileAdapterTest < Test::Unit::TestCase
def setup
p self
end
def teardown
report_files
end
context "a new instance" do
context "with normal file" do
setup do
@file = File.new(fixture_file("5k.png"))
@file.binmode
@subject = Paperclip.io_adapters.for(@file)
end
teardown do
@file.close
@subject.close
@subject.close if @subject
end
should "get the right filename" do
assert_equal "5k.png", @subject.original_filename
end
context 'doing normal things' do
setup do
@subject = Paperclip.io_adapters.for(@file)
end
should "force binmode on tempfile" do
assert @subject.instance_variable_get("@tempfile").binmode?
end
should "get the right filename" do
assert_equal "5k.png", @subject.original_filename
end
should "get the content type" do
assert_equal "image/png", @subject.content_type
end
should "force binmode on tempfile" do
assert @subject.instance_variable_get("@tempfile").binmode?
end
should "return content type as a string" do
assert_kind_of String, @subject.content_type
end
should "get the content type" do
assert_equal "image/png", @subject.content_type
end
should "get the file's size" do
assert_equal 4456, @subject.size
end
should "return content type as a string" do
assert_kind_of String, @subject.content_type
end
should "return false for a call to nil?" do
assert ! @subject.nil?
end
should "get the file's size" do
assert_equal 4456, @subject.size
end
should "generate a MD5 hash of the contents" do
expected = Digest::MD5.file(@file.path).to_s
assert_equal expected, @subject.fingerprint
end
should "return false for a call to nil?" do
assert ! @subject.nil?
end
should "read the contents of the file" do
expected = @file.read
assert expected.length > 0
assert_equal expected, @subject.read
should "generate a MD5 hash of the contents" do
expected = Digest::MD5.file(@file.path).to_s
assert_equal expected, @subject.fingerprint
end
should "read the contents of the file" do
expected = @file.read
assert expected.length > 0
assert_equal expected, @subject.read
end
end
context "file with multiple possible content type" do
setup do
MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-png'), MIME::Type.new('image/png')])
@subject = Paperclip.io_adapters.for(@file)
end
should "prefer officially registered mime type" do
......
......@@ -4,6 +4,7 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
def setup
rebuild_model
@dummy = Dummy.new
super
end
def build_validator(options)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment