=htc #18518 make it simpler to unmarshal csv values from params

This commit is contained in:
Konrad Malawski 2015-09-20 19:27:04 +01:00
parent e713591e5f
commit c9adfcfbc7
5 changed files with 49 additions and 3 deletions

View file

@ -7,6 +7,7 @@ package directives
import org.scalatest.{ FreeSpec, Inside }
import akka.http.scaladsl.unmarshalling.Unmarshaller.HexInt
import akka.http.scaladsl.unmarshalling.Unmarshaller.CsvString
class ParameterDirectivesSpec extends FreeSpec with GenericRoutingSpec with Inside {
"when used with 'as[Int]' the parameter directive should" - {
@ -52,6 +53,24 @@ class ParameterDirectivesSpec extends FreeSpec with GenericRoutingSpec with Insi
}
}
"when used with 'as(CsvString)' the parameter directive should" - {
val route =
parameter("names".as(CsvString)) { names
complete(s"The parameters are ${names.mkString(", ")}")
}
"extract a single name" in {
Get("/?names=Caplin") ~> route ~> check {
responseAs[String] shouldEqual "The parameters are Caplin"
}
}
"extract a number of names" in {
Get("/?names=Caplin,John") ~> route ~> check {
responseAs[String] shouldEqual "The parameters are Caplin, John"
}
}
}
"when used with 'as(HexInt)' the parameter directive should" - {
"extract parameter values as Int" in {
Get("/?amount=1f") ~> {