Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created October 7, 2009 10:19
Show Gist options
  • Save lukeredpath/203937 to your computer and use it in GitHub Desktop.
Save lukeredpath/203937 to your computer and use it in GitHub Desktop.
def file_upload_from_string(string, content_type = 'text/plain')
test_upload_file = nil
Tempfile.open('file_upload_from_string') do |tempfile|
tempfile.write(string)
tempfile.rewind
test_upload_file = ActionController::TestUploadedFile.new(tempfile.path, content_type)
end
return test_upload_file
end
# post :create, :my_params => {:uploaded_file => file_upload_from_string('foo')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment