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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
def test_delegates_to_tempfile
|
|
|
|
tf = Class.new { def tenderlove; 'thunderhorse' end }
|
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
|
|
|
assert_equal 'thunderhorse', uf.tenderlove
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delegates_to_tempfile_with_params
|
|
|
|
tf = Class.new { def tenderlove *args; args end }
|
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
|
|
|
assert_equal %w{ thunder horse }, uf.tenderlove(*%w{ thunder horse })
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delegates_to_tempfile_with_block
|
|
|
|
tf = Class.new { def tenderlove; yield end }
|
|
|
|
uf = Http::UploadedFile.new(:tempfile => tf.new)
|
|
|
|
assert_equal('thunderhorse', uf.tenderlove { 'thunderhorse' })
|
|
|
|
end
|
2010-10-04 19:30:16 -04:00
|
|
|
end
|
|
|
|
end
|