Last active
February 13, 2016 12:59
-
-
Save NTCoding/08ad009526194c51faf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| behavior of "vanilla play conditional mapping" | |
| it should "not contain an error for the conditional validation when there is a field-level error" in { | |
| val data = Map("nonUkResident" -> "true") | |
| val res = form.bind(data) | |
| assert(res.errors.length == 1) | |
| assert(res.errors.head.key === "email") | |
| } | |
| it should "not allow an field-level error message for a conditional validation" in { | |
| val data = Map("nonUkResident" -> "true", "email" -> "abc@gov.uk") | |
| val res = form.bind(data) | |
| assert(res.errors.length == 1) | |
| assert(res.errors.head.key === "") | |
| } | |
| lazy val form = Form(mapping( | |
| "nonUkResident" -> boolean, | |
| "country" -> optional(nonEmptyText), | |
| "email" -> nonEmptyText | |
| )(Model.apply)(Model.unapply).verifying("Error.countryRequired", x => x.nonUkResident && x.country.isDefined)) | |
| case class Model(nonUkResident: Boolean, country: Option[String], email: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment