Skip to content

Commit

Permalink
Merge pull request rails#7786 from yabawock/3-2-stable
Browse files Browse the repository at this point in the history
Backport "Don't paramify ActionDispatch::Http::UploadedFile in tests"
  • Loading branch information
rafaelfranca committed Sep 29, 2012
2 parents e1a10b1 + c53e5de commit c2a7084
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions actionpack/CHANGELOG.md
Expand Up @@ -46,6 +46,12 @@

*Jeremy Kemper & Erich Menge*

* Handle `ActionDispatch::Http::UploadedFile` like `Rack::Test::UploadedFile`, don't call to_param on it. Since
`Rack::Test::UploadedFile` isn't API compatible this is needed to test file uploads that rely on `tempfile`
being available.

*Tim Vandecasteele*


## Rails 3.2.8 (Aug 9, 2012) ##

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/test_case.rb
Expand Up @@ -422,7 +422,7 @@ def paramify_values(hash_or_array_or_value)
Hash[hash_or_array_or_value.map{|key, value| [key, paramify_values(value)] }]
when Array
hash_or_array_or_value.map {|i| paramify_values(i)}
when Rack::Test::UploadedFile
when Rack::Test::UploadedFile, ActionDispatch::Http::UploadedFile
hash_or_array_or_value
else
hash_or_array_or_value.to_param
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/test_test.rb
Expand Up @@ -766,6 +766,13 @@ def test_fixture_file_upload
assert_equal '159528', @response.body
end

def test_action_dispatch_uploaded_file_upload
filename = 'mona_lisa.jpg'
path = "#{FILES_DIR}/#{filename}"
post :test_file_upload, :file => ActionDispatch::Http::UploadedFile.new(:filename => path, :type => "image/jpg", :tempfile => File.open(path))
assert_equal '159528', @response.body
end

def test_test_uploaded_file_exception_when_file_doesnt_exist
assert_raise(RuntimeError) { Rack::Test::UploadedFile.new('non_existent_file') }
end
Expand Down

0 comments on commit c2a7084

Please sign in to comment.