+htp: #16651 Add formFieldMap, formFieldMultiMap & formFieldSeq Directives
This commit is contained in:
parent
ecc916abfd
commit
edf0d6cb21
8 changed files with 251 additions and 12 deletions
|
|
@ -44,5 +44,53 @@ class FormFieldDirectivesExamplesSpec extends RoutingSpec {
|
|||
responseAs[String] shouldEqual "Request is missing required form field 'color'"
|
||||
}
|
||||
}
|
||||
"formFieldMap" in {
|
||||
val route =
|
||||
formFieldMap { fields =>
|
||||
def formFieldString(formField: (String, String)): String =
|
||||
s"""${formField._1} = '${formField._2}'"""
|
||||
complete(s"The form fields are ${fields.map(formFieldString).mkString(", ")}")
|
||||
}
|
||||
|
||||
// tests:
|
||||
Post("/", FormData("color" -> "blue", "count" -> "42")) ~> route ~> check {
|
||||
responseAs[String] shouldEqual "The form fields are color = 'blue', count = '42'"
|
||||
}
|
||||
Post("/", FormData("x" -> "1", "x" -> "5")) ~> route ~> check {
|
||||
responseAs[String] shouldEqual "The form fields are x = '5'"
|
||||
}
|
||||
}
|
||||
"formFieldMultiMap" in {
|
||||
val route =
|
||||
formFieldMultiMap { fields =>
|
||||
complete("There are " +
|
||||
s"form fields ${fields.map(x => x._1 + " -> " + x._2.size).mkString(", ")}")
|
||||
}
|
||||
|
||||
// tests:
|
||||
Post("/", FormData("color" -> "blue", "count" -> "42")) ~> route ~> check {
|
||||
responseAs[String] shouldEqual "There are form fields color -> 1, count -> 1"
|
||||
}
|
||||
Post("/", FormData("x" -> "23", "x" -> "4", "x" -> "89")) ~> route ~> check {
|
||||
responseAs[String] shouldEqual "There are form fields x -> 3"
|
||||
}
|
||||
}
|
||||
"formFieldSeq" in {
|
||||
val route =
|
||||
formFieldSeq { fields =>
|
||||
def formFieldString(formField: (String, String)): String =
|
||||
s"""${formField._1} = '${formField._2}'"""
|
||||
complete(s"The form fields are ${fields.map(formFieldString).mkString(", ")}")
|
||||
}
|
||||
|
||||
// tests:
|
||||
Post("/", FormData("color" -> "blue", "count" -> "42")) ~> route ~> check {
|
||||
responseAs[String] shouldEqual "The form fields are color = 'blue', count = '42'"
|
||||
}
|
||||
Post("/", FormData("x" -> "23", "x" -> "4", "x" -> "89")) ~> route ~> check {
|
||||
responseAs[String] shouldEqual "The form fields are x = '23', x = '4', x = '89'"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue