2010-10-04 19:30:16 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
class UploadedFileTest < ActiveSupport::TestCase
|
2010-10-04 20:08:25 -04:00
|
|
|
def test_constructor_with_argument_error
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
Http::UploadedFile.new({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-04 19:30:16 -04:00
|
|
|
def test_original_filename
|
2010-10-04 20:08:25 -04:00
|
|
|
uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new)
|
2010-10-04 19:30:16 -04:00
|
|
|
assert_equal 'foo', uf.original_filename
|
|
|
|
end
|
2011-06-14 03:59:18 -04:00
|
|
|
|
|
|
|
if "ruby".encoding_aware?
|
2011-06-14 10:58:06 -04:00
|
|
|
def test_filename_should_be_in_utf_8
|
2011-06-14 03:59:18 -04:00
|
|
|
uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new)
|
2011-06-15 06:09:27 -04:00
|
|
|
assert_equal "UTF-8", uf.original_filename.encoding.to_s
|
2011-06-14 03:59:18 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-04 19:30:16 -04:00
|
|
|
|
|
|
|
def test_content_type
|
2010-10-04 20:08:25 -04:00
|
|
|
uf = Http::UploadedFile.new(:type => 'foo', :tempfile => Object.new)
|
2010-10-04 19:30:16 -04:00
|
|
|
assert_equal 'foo', uf.content_type
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_headers
|
2010-10-04 20:08:25 -04:00
|
|
|
uf = Http::UploadedFile.new(:head => 'foo', :tempfile => Object.new)
|
2010-10-04 19:30:16 -04:00
|
|
|
assert_equal 'foo', uf.headers
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tempfile
|
|
|
|
uf = Http::UploadedFile.new(:tempfile => 'foo')
|
|
|
|
assert_equal 'foo', uf.tempfile
|
|
|
|
end
|
2010-10-04 19:56:45 -04:00
|
|
|
|
2010-11-18 13:10:18 -05:00
|
|
|
def test_delegates_path_to_tempfile
|
|
|
|
tf = Class.new { def path; 'thunderhorse' end }
|
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
|
|
|
assert_equal 'thunderhorse', uf.path
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delegates_open_to_tempfile
|
|
|
|
tf = Class.new { def open; 'thunderhorse' end }
|
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
|
|
|
assert_equal 'thunderhorse', uf.open
|
|
|
|
end
|
|
|
|
|
2010-10-04 19:56:45 -04:00
|
|
|
def test_delegates_to_tempfile
|
2010-10-04 22:28:40 -04:00
|
|
|
tf = Class.new { def read; 'thunderhorse' end }
|
2010-10-04 19:56:45 -04:00
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
2010-10-04 22:28:40 -04:00
|
|
|
assert_equal 'thunderhorse', uf.read
|
2010-10-04 19:56:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_delegates_to_tempfile_with_params
|
2010-10-04 22:28:40 -04:00
|
|
|
tf = Class.new { def read *args; args end }
|
2010-10-04 19:56:45 -04:00
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
2010-10-04 22:28:40 -04:00
|
|
|
assert_equal %w{ thunder horse }, uf.read(*%w{ thunder horse })
|
2010-10-04 19:56:45 -04:00
|
|
|
end
|
2010-10-04 20:11:50 -04:00
|
|
|
|
|
|
|
def test_delegate_respects_respond_to?
|
2010-10-04 22:28:40 -04:00
|
|
|
tf = Class.new { def read; yield end; private :read }
|
2010-10-04 20:11:50 -04:00
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
|
|
|
assert_raises(NoMethodError) do
|
2010-10-04 22:28:40 -04:00
|
|
|
uf.read
|
2010-10-04 20:11:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_respond_to?
|
2010-10-04 22:28:40 -04:00
|
|
|
tf = Class.new { def read; yield end }
|
2010-10-04 20:11:50 -04:00
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
|
|
|
assert uf.respond_to?(:headers), 'responds to headers'
|
2010-10-04 22:28:40 -04:00
|
|
|
assert uf.respond_to?(:read), 'responds to read'
|
2010-10-04 20:11:50 -04:00
|
|
|
end
|
2010-10-04 19:30:16 -04:00
|
|
|
end
|
|
|
|
end
|