Commit 726f183c by Jon Yurek

WIP

parent fb13e2ec
...@@ -32,6 +32,7 @@ end ...@@ -32,6 +32,7 @@ end
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..'))) ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
$previous_count = 0
class Test::Unit::TestCase class Test::Unit::TestCase
def setup def setup
silence_warnings do silence_warnings do
...@@ -42,8 +43,21 @@ class Test::Unit::TestCase ...@@ -42,8 +43,21 @@ class Test::Unit::TestCase
end end
end end
def teardown
report_files
end
def report_files 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
end end
......
require './test/helper' 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 class AttachmentAdapterTest < Test::Unit::TestCase
def setup def setup
...@@ -7,10 +25,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase ...@@ -7,10 +25,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
end end
def teardown
report_files
end
context "for an attachment" do context "for an attachment" do
setup do setup do
@file = File.new(fixture_file("5k.png")) @file = File.new(fixture_file("5k.png"))
...@@ -22,7 +36,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase ...@@ -22,7 +36,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end end
teardown do teardown do
@subject.close
@file.close @file.close
end end
...@@ -63,8 +76,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase ...@@ -63,8 +76,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
context "for a file with restricted characters in the name" do context "for a file with restricted characters in the name" do
setup do setup do
file_contents = File.new(fixture_file("animated.gif")) file_contents = IO.read(fixture_file("animated.gif"))
@file = StringIO.new(file_contents.read) @file = StringIO.new(file_contents)
@file.stubs(:original_filename).returns('image:restricted.gif') @file.stubs(:original_filename).returns('image:restricted.gif')
@file.binmode @file.binmode
...@@ -74,7 +87,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase ...@@ -74,7 +87,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end end
teardown do teardown do
@file.close @subject.close
end end
should "not generate paths that include restricted characters" do should "not generate paths that include restricted characters" do
......
require './test/helper' 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 class FileAdapterTest < Test::Unit::TestCase
def setup
p self
end
def teardown
report_files
end
context "a new instance" do context "a new instance" do
context "with normal file" do context "with normal file" do
setup do setup do
@file = File.new(fixture_file("5k.png")) @file = File.new(fixture_file("5k.png"))
@file.binmode @file.binmode
@subject = Paperclip.io_adapters.for(@file)
end end
teardown do teardown do
@file.close @file.close
@subject.close @subject.close if @subject
end end
should "get the right filename" do context 'doing normal things' do
assert_equal "5k.png", @subject.original_filename setup do
end @subject = Paperclip.io_adapters.for(@file)
end
should "force binmode on tempfile" do should "get the right filename" do
assert @subject.instance_variable_get("@tempfile").binmode? assert_equal "5k.png", @subject.original_filename
end end
should "get the content type" do should "force binmode on tempfile" do
assert_equal "image/png", @subject.content_type assert @subject.instance_variable_get("@tempfile").binmode?
end end
should "return content type as a string" do should "get the content type" do
assert_kind_of String, @subject.content_type assert_equal "image/png", @subject.content_type
end end
should "get the file's size" do should "return content type as a string" do
assert_equal 4456, @subject.size assert_kind_of String, @subject.content_type
end end
should "return false for a call to nil?" do should "get the file's size" do
assert ! @subject.nil? assert_equal 4456, @subject.size
end end
should "generate a MD5 hash of the contents" do should "return false for a call to nil?" do
expected = Digest::MD5.file(@file.path).to_s assert ! @subject.nil?
assert_equal expected, @subject.fingerprint end
end
should "read the contents of the file" do should "generate a MD5 hash of the contents" do
expected = @file.read expected = Digest::MD5.file(@file.path).to_s
assert expected.length > 0 assert_equal expected, @subject.fingerprint
assert_equal expected, @subject.read end
should "read the contents of the file" do
expected = @file.read
assert expected.length > 0
assert_equal expected, @subject.read
end
end end
context "file with multiple possible content type" do context "file with multiple possible content type" do
setup do setup do
MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-png'), MIME::Type.new('image/png')]) MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-png'), MIME::Type.new('image/png')])
@subject = Paperclip.io_adapters.for(@file)
end end
should "prefer officially registered mime type" do should "prefer officially registered mime type" do
......
...@@ -4,6 +4,7 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase ...@@ -4,6 +4,7 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
def setup def setup
rebuild_model rebuild_model
@dummy = Dummy.new @dummy = Dummy.new
super
end end
def build_validator(options) 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