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
context 'doing normal things' do
setup do
@subject = Paperclip.io_adapters.for(@file)
end end
should "get the right filename" do should "get the right filename" do
...@@ -72,10 +52,12 @@ class FileAdapterTest < Test::Unit::TestCase ...@@ -72,10 +52,12 @@ class FileAdapterTest < Test::Unit::TestCase
assert expected.length > 0 assert expected.length > 0
assert_equal expected, @subject.read 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