Skip to content

Commit

Permalink
raising an argument error if tempfile is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 5, 2010
1 parent 876acf0 commit 8a97470
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_dispatch/http/upload.rb
Expand Up @@ -10,6 +10,7 @@ def initialize(hash)
@content_type = hash[:type]
@headers = hash[:head]
@tempfile = hash[:tempfile]
raise(ArgumentError, ':tempfile is required') unless @tempfile
end

def method_missing(name, *args, &block)
Expand Down
12 changes: 9 additions & 3 deletions actionpack/test/dispatch/uploaded_file_test.rb
Expand Up @@ -2,18 +2,24 @@

module ActionDispatch
class UploadedFileTest < ActiveSupport::TestCase
def test_constructor_with_argument_error
assert_raises(ArgumentError) do
Http::UploadedFile.new({})
end
end

def test_original_filename
uf = Http::UploadedFile.new(:filename => 'foo')
uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new)
assert_equal 'foo', uf.original_filename
end

def test_content_type
uf = Http::UploadedFile.new(:type => 'foo')
uf = Http::UploadedFile.new(:type => 'foo', :tempfile => Object.new)
assert_equal 'foo', uf.content_type
end

def test_headers
uf = Http::UploadedFile.new(:head => 'foo')
uf = Http::UploadedFile.new(:head => 'foo', :tempfile => Object.new)
assert_equal 'foo', uf.headers
end

Expand Down

0 comments on commit 8a97470

Please sign in to comment.