Skip to content
Permalink
Browse files

dave - added rebinding of form objects

  • Loading branch information...
daviddenton committed Jul 12, 2015
1 parent f2bb628 commit 49b07be2a1775d300410c0114e38bac49238e24c
@@ -3,7 +3,6 @@ Roadmap/Release Notes/Migration Guide
The main API is fairly stable now, but expect some amount of breaking changes around major releases as new features are added.

######Master (in dev...)
- Improve support for Forms and custom Body types in Clientside APIs.
- Strictness checks around accepted content types, resulting in Unsupported Media Type (415) in case of mismatch.

#####v7.2.0
@@ -13,7 +13,8 @@ import scala.util.{Failure, Success, Try}

class FormBody(fields: Seq[FormField[_] with Retrieval[_, Form]])
extends Body[Form](FormBody.spec)
with Bindable[Form, Binding] {
with Bindable[Form, Binding]
with MandatoryRebind[Form, HttpRequest, Binding] {

override def -->(value: Form): Seq[Binding] = {
Seq(new RequestBinding(null, t => {
@@ -21,7 +21,7 @@ class UniBody[T](spec: BodySpec[T],
theExample: Option[JsonRootNode])
extends Body[T](spec)
with Bindable[T, RequestBinding]
with MandatoryRebind[T, HttpRequest, RequestBinding]{
with MandatoryRebind[T, HttpRequest, RequestBinding] {

private val param = new BodyParameter[T] with Bindable[T, RequestBinding] {
override val required = true
@@ -38,6 +38,18 @@ class BodyTest extends FunSpec with ShouldMatchers {
val deserializedForm = formBody from request
deserializedForm shouldEqual inputForm
}

it("can rebind valid value") {
val date = FormField.required.localDate("date")
val inputForm = Form(date --> LocalDate.of(1976, 8, 31))
val formBody = Body.form(date)
val bindings = formBody --> inputForm
val inRequest = bindings.foldLeft(RequestBuild()) { (requestBuild, next) => next(requestBuild) }.build(HttpMethod.GET)
val rebindings = formBody <-> inRequest
val outRequest = rebindings.foldLeft(RequestBuild()) { (requestBuild, next) => next(requestBuild) }.build(HttpMethod.GET)
val deserializedForm = formBody from outRequest
deserializedForm shouldEqual inputForm
}
}

describe("json") {

0 comments on commit 49b07be

Please sign in to comment.
You can’t perform that action at this time.