# Testing for multipart form uploads

**URL:** <https://www.ruby-forum.com/t/testing-for-multipart-form-uploads/92869>\
**Category:** Rails\
**Created:** [April 25, 2007, 8:18am UTC](https://www.ruby-forum.com/t/testing-for-multipart-form-uploads/92869 "2007-04-25T08:18:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [April 25, 2007, 8:18am UTC](https://www.ruby-forum.com/t/testing-for-multipart-form-uploads/92869/1 "2007-04-25T08:18:40Z")

</div>

Hi,

I’m trying to do integration tests that require uploading files via  
multipart posts.

Have seen a very similar discussion, but cannot get it to work. Maybe,  
it’s out of date now with Rails 1.2.3:  
[http://groups.google.ca/group/rubyonrails-talk/browse\_thread/thread/fdfd2c040a2425f4](http://groups.google.ca/group/rubyonrails-talk/browse_thread/thread/fdfd2c040a2425f4)

> From what I understand, fixture\_file\_upload’s output is translated a  
> String. There’s a ticket discussing this here:  
> [http://dev.rubyonrails.org/ticket/4635](http://dev.rubyonrails.org/ticket/4635)  
> The solution there is to use code that does the multipart encoding:  
> integration\_test\_file\_upload.rb

Again, it doesn’t work. The file I’m getting is a truncated version of  
the original.

This is my code:

fdata = fixture\_file\_upload(fname,‘application/octet-stream’)  
multipart\_post  
url\_for(:controller=\>:support\_files, :action=\>:create),  
:session=\>session,  
:project\_id=\>project\_id,  
:support\_file=\>{‘uploaded\_data’=\>fdata},  
:format=\>‘xml’

BTW: On the other side, I’m using acts\_as\_attachment to process the  
multipart data. It works fine when I’m using a browser to upload.

Any recommendations on how to get this to work in an integration  
testing environment?

Thanks,  
Helzer

---

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [May 23, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/testing-for-multipart-form-uploads/92869/2 "2007-05-23T16:25:20Z")

</div>

A quick update, if anyone’s interested:

The solution, shown in the ticket below, actually works fine AFTER I  
fixed the file read to open in mode ‘rb’ and not ‘r’.  
[http://groups.google.ca/group/rubyonrails-talk/browse\_thread/thread/fdfd2c040a2425f4](http://groups.google.ca/group/rubyonrails-talk/browse_thread/thread/fdfd2c040a2425f4)

Amir
