Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lift-record

  • Loading branch information...
commit ff654188a87aae41583ea6a3a56f58c322272dfe 1 parent 15b7d73
@nafg nafg authored
View
79 persistence/record/src/test/scala/net/liftweb/record/FieldSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2011 WorldWide Conferencing, LLC
+ * Copyright 2010-2012 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@ import json.JsonAST._
import util.Helpers._
import java.util.Calendar
-import org.specs._
-import org.specs.runner.{ConsoleRunner, JUnit3}
+import org.specs2.mutable._
+import org.specs2.specification.Fragment
import fixtures._
import net.liftweb.util.{Helpers, FieldError}
@@ -38,20 +38,20 @@ import scala.xml.{NodeSeq, Elem, Node, Text}
/**
* Systems under specification for RecordField.
*/
-object FieldSpec extends Specification("Record Field Specification") {
- val session = new LiftSession("", randomString(20), Empty)
- def inLiftSession(a: =>Any) = S.initIfUninitted(session) { a }
- new SpecContext {
- aroundExpectations(inLiftSession(_))
- }
- def passBasicTests[A](example: A, mandatory: MandatoryTypedField[A], legacyOptional: MandatoryTypedField[A], optional: OptionalTypedField[A])(implicit m: scala.reflect.Manifest[A]): Unit = {
+object FieldSpec extends Specification {
+ "Record Field Specification".title
+ sequential
+
+ lazy val session = new LiftSession("", randomString(20), Empty)
+
+ def passBasicTests[A](example: A, mandatory: MandatoryTypedField[A], legacyOptional: MandatoryTypedField[A], optional: OptionalTypedField[A])(implicit m: scala.reflect.Manifest[A]): Fragment = {
val canCheckDefaultValues =
!mandatory.defaultValue.isInstanceOf[Calendar] // don't try to use the default value of date/time typed fields, because it changes from moment to moment!
-
+
def commonBehaviorsForMandatory(in: MandatoryTypedField[A]): Unit = {
if (canCheckDefaultValues) {
- "which have the correct initial value" in {
+ "which have the correct initial value" in S.initIfUninitted(session) {
in.get must_== in.defaultValue
}
}
@@ -63,6 +63,8 @@ object FieldSpec extends Specification("Record Field Specification") {
in.get must_!= example
in.setBox(Box !! example)
in.get must_== example
+ in.clear
+ success
}
if (canCheckDefaultValues) {
@@ -73,9 +75,8 @@ object FieldSpec extends Specification("Record Field Specification") {
}
}
}
-
+
def commonBehaviorsForAllFlavors(in: TypedField[A]): Unit = {
-
if (canCheckDefaultValues) {
"which have the correct initial boxed value" in {
in match {
@@ -87,28 +88,31 @@ object FieldSpec extends Specification("Record Field Specification") {
}
}
- "which have readable and writable boxed values" in {
+ "which have readable and writable boxed values" in S.initIfUninitted(session) {
in.setBox(Full(example))
- in.valueBox must verify(_.isDefined)
+ in.valueBox.isDefined must_== true
in.valueBox must_== Full(example)
in.clear
in.valueBox must_!= Full(example)
}
if (canCheckDefaultValues) {
- "which correctly clear back to the default box value" in {
+ "which correctly clear back to the default box value" in S.initIfUninitted(session) {
in.setBox(Full(example))
- in.valueBox must verify(_.isDefined)
+ in.valueBox.isDefined must_== true
in.clear
in.valueBox must_== in.defaultValueBox
}
}
"which capture error conditions set in" in {
+ val old = in.valueBox
in.setBox(Failure("my failure"))
in.valueBox must_== Failure("my failure")
+ in.setBox(old)
+ success
}
-
+
if(canCheckDefaultValues) {
"which are only flagged as dirty_? when setBox is called with a different value" in {
in.clear
@@ -123,9 +127,11 @@ object FieldSpec extends Specification("Record Field Specification") {
in.setBox(valueBox)
in.dirty_? must_== false
val exampleBox = Full(example)
- valueBox must verify { v => ! (exampleBox === v) }
+ (valueBox === exampleBox) must_== false
in.setBox(exampleBox)
in.dirty_? must_== true
+ in.setBox(valueBox)
+ success
}
}
}
@@ -137,22 +143,22 @@ object FieldSpec extends Specification("Record Field Specification") {
"which are configured correctly" in {
mandatory.optional_? must_== false
}
-
+
"which initialize to some value" in {
- mandatory.valueBox must verify(_.isDefined)
+ mandatory.valueBox.isDefined must_== true
}
"which correctly fail to be set to Empty" in {
- mandatory.valueBox must verify(_.isDefined)
+ mandatory.valueBox.isDefined must_== true
mandatory.setBox(Empty)
- mandatory.valueBox must beLike { case Failure(s, _, _) if s == mandatory.notOptionalErrorMessage => true }
+ mandatory.valueBox must beLike { case Failure(s, _, _) => s must_== mandatory.notOptionalErrorMessage}
}
}
"support 'legacy' optional fields (override optional_?)" in {
commonBehaviorsForAllFlavors(legacyOptional)
commonBehaviorsForMandatory(legacyOptional)
-
+
"which are configured correctly" in {
legacyOptional.optional_? must_== true
}
@@ -178,6 +184,7 @@ object FieldSpec extends Specification("Record Field Specification") {
legacyOptional.value must_== legacyOptional.defaultValue
legacyOptional.valueBox must_== legacyOptional.defaultValueBox
}
+ success
}
}
@@ -209,9 +216,9 @@ object FieldSpec extends Specification("Record Field Specification") {
}
}
- def passConversionTests[A](example: A, mandatory: MandatoryTypedField[A], jsexp: JsExp, jvalue: JValue, formPattern: Box[NodeSeq]): Unit = {
+ def passConversionTests[A](example: A, mandatory: MandatoryTypedField[A], jsexp: JsExp, jvalue: JValue, formPattern: Box[NodeSeq]): Fragment = {
- "convert to JsExp" in {
+ "convert to JsExp" in S.initIfUninitted(session) {
mandatory.set(example)
mandatory.asJs mustEqual jsexp
}
@@ -226,7 +233,6 @@ object FieldSpec extends Specification("Record Field Specification") {
"get set from JValue" in {
mandatory.setFromJValue(jvalue) mustEqual Full(example)
mandatory.value mustEqual example
- () // does not compile without this: no implicit argument matching parameter type scala.reflect.Manifest[org.specs.specification.Result[mandatory.MyType]]
}
}
@@ -236,8 +242,8 @@ object FieldSpec extends Specification("Record Field Specification") {
val session = new LiftSession("", randomString(20), Empty)
S.initIfUninitted(session) {
val formXml = mandatory.toForm
- formXml must notBeEmpty
- formXml foreach { fprime =>
+ formXml.isDefined must_== true
+ formXml.toList map { fprime =>
val f = ("* [name]" #> ".*" & "select *" #> (((ns: NodeSeq) => ns.filter {
case e: Elem => e.attribute("selected").map(_.text) == Some("selected")
case _ => false
@@ -248,6 +254,7 @@ object FieldSpec extends Specification("Record Field Specification") {
}
}
}
+ success
}
/* Since Array[Byte]s cannot be compared, commenting out this test for now
@@ -407,7 +414,7 @@ object FieldSpec extends Specification("Record Field Specification") {
}
"PasswordField" should {
- "require a nonempty password" in {
+ "require a nonempty password" in S.initIfUninitted(session) {
val rec = PasswordTestRecord.createRecord.password("")
rec.validate must_== (
@@ -416,10 +423,10 @@ object FieldSpec extends Specification("Record Field Specification") {
)
}
- "correctly validate the unencrypted value" in {
+ "correctly validate the unencrypted value" in S.initIfUninitted(session) {
val rec = PasswordTestRecord.createRecord.password("testvalue")
rec.validate must_== Nil
-
+
rec.password("1234")
rec.validate must_== (
FieldError(rec.password, Text(S.?("password.too.short"))) ::
@@ -430,10 +437,10 @@ object FieldSpec extends Specification("Record Field Specification") {
"match with encrypted value" in {
val rec = PasswordTestRecord.createRecord.password("testpassword")
rec.password.match_?("testpassword") must_== true
-
+
rec.password.set("$2a$10$6CJWdXpKoP8bVTjGH8SbKOWevNQVL8MkYVlBLmqtywVi7dp/YgPXC")
rec.password.match_?("dummyPassw0rd") must_== true
- }
+ }
}
"PostalCodeField" should {
@@ -476,7 +483,7 @@ object FieldSpec extends Specification("Record Field Specification") {
"honor harnessed validators" in {
val rec = ValidationTestRecord.createRecord
val field = rec.stringFieldWithValidation
-
+
"which always succeed" in {
field.validationHarness = _ => Nil
rec.validate must_== Nil
View
3  persistence/record/src/test/scala/net/liftweb/record/Fixtures.scala
@@ -22,8 +22,7 @@ import java.math.MathContext
import scala.xml.Text
import common.{Box, Empty, Full}
import util.{FieldError, Helpers}
-import org.specs._
-import org.specs.runner.{ConsoleRunner, JUnit3}
+import org.specs2.mutable._
import field._
View
39 persistence/record/src/test/scala/net/liftweb/record/RecordSpec.scala
@@ -19,7 +19,9 @@ package record
import java.util.Calendar
-import org.specs.Specification
+import org.specs2.mutable.Specification
+import org.specs2.specification.Fragment
+
import util.Helpers._
import json.JsonAST.JField
import json.JsonAST.JInt
@@ -29,8 +31,6 @@ import json.JsonAST.JObject
import json.JsonAST.JDouble
import json.JsonAST.JBool
-//import org.specs.Specification.
-
import json.JsonAST._
import util._
import http.js.JE._
@@ -44,12 +44,9 @@ import common.Empty
/**
* Systems under specification for Record.
*/
-object RecordSpec extends Specification("Record Specification") {
- val session = new LiftSession("", randomString(20), Empty)
- def inLiftSession(a: =>Any) = S.initIfUninitted(session) { a }
- new SpecContext {
- aroundExpectations(inLiftSession(_))
- }
+object RecordSpec extends Specification {
+ "Record Specification".title
+
"Record field introspection" should {
val rec = FieldTypeTestRecord.createRecord
val allExpectedFieldNames: List[String] = (for {
@@ -62,14 +59,14 @@ object RecordSpec extends Specification("Record Specification") {
}
"correctly look up fields by name" in {
- for (name <- allExpectedFieldNames) {
- rec.fieldByName(name) must verify(_.isDefined)
+ for (name <- allExpectedFieldNames) yield {
+ rec.fieldByName(name).isDefined must_== true
}
}
"not look up fields by bogus names" in {
- for (name <- allExpectedFieldNames) {
- rec.fieldByName("x" + name + "y") must not(verify(_.isDefined))
+ for (name <- allExpectedFieldNames) yield {
+ rec.fieldByName("x" + name + "y").isDefined must_== false
}
}
@@ -80,7 +77,7 @@ object RecordSpec extends Specification("Record Specification") {
}
"Record lifecycle callbacks" should {
- def testOneHarness(scope: String, f: LifecycleTestRecord => HarnessedLifecycleCallbacks): Unit = {
+ def testOneHarness(scope: String, f: LifecycleTestRecord => HarnessedLifecycleCallbacks): Fragment = {
("be called before validation when specified at " + scope) in {
val rec = LifecycleTestRecord.createRecord
var triggered = false
@@ -251,7 +248,9 @@ object RecordSpec extends Specification("Record Specification") {
)
"convert to JsExp (via asJSON)" in {
- fttr.asJSON mustEqual fttrAsJsObj
+ S.initIfUninitted(new LiftSession("", randomString(20), Empty)) {
+ fttr.asJSON mustEqual fttrAsJsObj
+ }
}
/* Test broken
@@ -311,8 +310,8 @@ object RecordSpec extends Specification("Record Specification") {
"get set from json string using lift-json parser" in {
val fttrFromJson = FieldTypeTestRecord.fromJsonString(json)
- fttrFromJson must notBeEmpty
- fttrFromJson foreach { r =>
+ fttrFromJson.isDefined must_== true
+ fttrFromJson.toList map { r =>
r.mandatoryDecimalField.value mustEqual fttr.mandatoryDecimalField.value
r mustEqual fttr
}
@@ -320,14 +319,14 @@ object RecordSpec extends Specification("Record Specification") {
"get set from json string using util.JSONParser" in {
val fttrFromJSON = FieldTypeTestRecord.fromJSON(json)
- fttrFromJSON must notBeEmpty
- fttrFromJSON foreach { r =>
+ fttrFromJSON.isDefined must_== true
+ fttrFromJSON.toList map { r =>
r mustEqual fttr
}
}
}
}
-
+
"basic record" should {
"order fields according to fieldOrder" in {
BasicTestRecord.metaFields must_== List(BasicTestRecord.field2, BasicTestRecord.field1, BasicTestRecord.field3)

1 comment on commit ff65418

@fmpwizard
Owner

+1

Please sign in to comment.
Something went wrong with that request. Please try again.