Faking a multipart form upload with webrat
We’re developing an API of sorts for one of our clients. We’ve got an API that expects some form data for an Item and an optional file sent along. We ran into a little bit of trouble sending this file along with the request. We took a cue from the way webrat submits its forms for our solution:
file = File.open("path/to/fixtured/file")
params = { :item => {:new_file => ActionController::TestUploadedFile.new(file.path)} }
visit api_item_path(item), :put, params