=htc #18518 make it simpler to unmarshal csv values from params
This commit is contained in:
parent
e713591e5f
commit
c9adfcfbc7
5 changed files with 49 additions and 3 deletions
|
|
@ -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") ~> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue