scalatra/scalatra — pull request #168 by mnylen (2012-04-07 09:37:36+00:00)
Title: Supporting methods for testing multipart/form-data file uploads

Adds overloaded post() and put() methods with additional Map[String, File] parameter to ScalatraTests. These generate multipart/form-data requests from files and eases testing of file uploads to Scalatra servlets with FileUploadSupport enabled.

Example usage:

class FileUploadSpec extends Specification {
"POST /upload" should {
"return status 200" in {
post("/upload", Map(), Map("kitten" -> new File("kitten.png"))) {
status must_== 200
}
}
}
}

Also, as commons-fileupload allows for only POST requests to be considered as multipart requests, an improved isMultipartContent method was added to FileUploadSupport that allows both PUT and POST requests. Without this fix, PUT requests with multipart content work, but the params map is never populated.