Commit fb13e2ec by Jon Yurek

Print all the files!

parent 14469310
...@@ -11,3 +11,5 @@ platform :ruby do ...@@ -11,3 +11,5 @@ platform :ruby do
gem 'pry' gem 'pry'
gem 'pry-debugger' gem 'pry-debugger'
end end
gem "cocaine", :path => "/Users/jyurek/Development/cocaine"
...@@ -8,6 +8,7 @@ class ContentTypeDetectorTest < Test::Unit::TestCase ...@@ -8,6 +8,7 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
should 'return the empty content type when the file is empty' do should 'return the empty content type when the file is empty' do
tempfile = Tempfile.new("empty") tempfile = Tempfile.new("empty")
assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect
tempfile.close
end end
should 'return content type of file if it is an acceptable type' do should 'return content type of file if it is an acceptable type' do
......
...@@ -7,6 +7,8 @@ class FileCommandContentTypeDetectorTest < Test::Unit::TestCase ...@@ -7,6 +7,8 @@ class FileCommandContentTypeDetectorTest < Test::Unit::TestCase
tempfile.rewind tempfile.rewind
assert_equal "text/plain", Paperclip::FileCommandContentTypeDetector.new(tempfile.path).detect assert_equal "text/plain", Paperclip::FileCommandContentTypeDetector.new(tempfile.path).detect
tempfile.close
end end
should 'return a sensible default when the file command is missing' do should 'return a sensible default when the file command is missing' do
......
...@@ -41,6 +41,10 @@ class Test::Unit::TestCase ...@@ -41,6 +41,10 @@ class Test::Unit::TestCase
Rails.stubs(:const_defined?).with(:Railtie).returns(false) Rails.stubs(:const_defined?).with(:Railtie).returns(false)
end end
end end
def report_files
ObjectSpace.each_object(IO){|io| puts "Open IO: #{io.inspect}" unless io.closed? }
end
end end
$LOAD_PATH << File.join(ROOT, 'lib') $LOAD_PATH << File.join(ROOT, 'lib')
......
...@@ -7,6 +7,10 @@ class AttachmentAdapterTest < Test::Unit::TestCase ...@@ -7,6 +7,10 @@ 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"))
...@@ -18,6 +22,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase ...@@ -18,6 +22,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end end
teardown do teardown do
@subject.close
@file.close @file.close
end end
......
require './test/helper' require './test/helper'
class DataUriAdapterTest < Test::Unit::TestCase class DataUriAdapterTest < Test::Unit::TestCase
def teardown
if @subject
@subject.close
end
end
context "a new instance" do context "a new instance" do
setup do setup do
@contents = "data:image/png;base64,#{original_base64_content}" @contents = "data:image/png;base64,#{original_base64_content}"
......
require './test/helper' require './test/helper'
class EmptyStringAdapterTest < Test::Unit::TestCase class EmptyStringAdapterTest < Test::Unit::TestCase
def teardown
if @subject
@subject.close
end
end
context 'a new instance' do context 'a new instance' do
setup do setup do
@subject = Paperclip.io_adapters.for('') @subject = Paperclip.io_adapters.for('')
......
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
...@@ -9,7 +33,10 @@ class FileAdapterTest < Test::Unit::TestCase ...@@ -9,7 +33,10 @@ class FileAdapterTest < Test::Unit::TestCase
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
teardown { @file.close } teardown do
@file.close
@subject.close
end
should "get the right filename" do should "get the right filename" do
assert_equal "5k.png", @subject.original_filename assert_equal "5k.png", @subject.original_filename
...@@ -86,13 +113,17 @@ class FileAdapterTest < Test::Unit::TestCase ...@@ -86,13 +113,17 @@ class FileAdapterTest < Test::Unit::TestCase
context "filename with restricted characters" do context "filename with restricted characters" do
setup do setup do
file_contents = File.new(fixture_file("animated.gif")) @file = File.open(fixture_file("animated.gif")) do |file|
@file = StringIO.new(file_contents.read) StringIO.new(file.read)
end
@file.stubs(:original_filename).returns('image:restricted.gif') @file.stubs(:original_filename).returns('image:restricted.gif')
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
teardown { @file.close } teardown do
@file.close
@subject.close
end
should "not generate filenames that include restricted characters" do should "not generate filenames that include restricted characters" do
assert_equal 'image_restricted.gif', @subject.original_filename assert_equal 'image_restricted.gif', @subject.original_filename
...@@ -109,7 +140,10 @@ class FileAdapterTest < Test::Unit::TestCase ...@@ -109,7 +140,10 @@ class FileAdapterTest < Test::Unit::TestCase
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
teardown { @file.close } teardown do
@file.close
@subject.close
end
should "provide correct mime-type" do should "provide correct mime-type" do
assert_match %r{.*/x-empty}, @subject.content_type assert_match %r{.*/x-empty}, @subject.content_type
......
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