forked from playframework/playframework
/
FormSpec.scala
62 lines (42 loc) · 1.14 KB
/
FormSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package test
import org.specs2.mutable.Specification
import play.api.test._
import play.api.test.Helpers._
import play.api.data._
import play.api.data.Forms._
object Dummyform {
def provide = Form(
tuple(
"email" -> Forms.text,
"address" -> optional(
single("city" -> nonEmptyText)
)
)
)
}
class FormSpec extends Specification {
val userForm = Dummyform.provide
"the userForm" should {
"don't bind the address if missing" in {
val (email, address) = userForm.bind(
Map("email" -> "coco")
).get
email must equalTo("coco")
address must beNone
}
"don't bind the address if blank" in {
val (email, address) = userForm.bind(
Map("email" -> "coco", "address.city" -> "")
).get
email must equalTo("coco")
address must beNone
}
"bind the address" in {
val (email, address) = userForm.bind(
Map("email" -> "coco", "address.city" -> "Paris")
).get
email must equalTo("coco")
address must beSome.which(_ == "Paris")
}
}
}