Forum: Ruby on Rails Testing for multipart form uploads

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dc218395c242f9feb76c62aea1183874?d=identicon&s=25 helzer (Guest)
on 2007-04-25 08:18
(Received via mailing list)
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/bro...

>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
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
Dc218395c242f9feb76c62aea1183874?d=identicon&s=25 helzer (Guest)
on 2007-05-23 16:25
(Received via mailing list)
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/bro...

Amir
This topic is locked and can not be replied to.