Skip to content
Browse files

lift-mongodb-record

  • Loading branch information...
1 parent ff65418 commit d9dacced699a073f91846c345f6e33c196af1c38 @nafg nafg committed Aug 1, 2012
View
21 ...ence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/CustomSerializersSpec.scala
@@ -28,7 +28,7 @@ import util.Helpers._
import java.util.{Calendar, Date}
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
import net.liftweb.record.field._
import xml.{Elem, NodeSeq}
@@ -152,7 +152,8 @@ object EnumRec extends EnumRec with MongoMetaRecord[EnumRec] {
/**
* Systems under specification for CustomSerializers.
*/
-object CustomSerializersSpec extends Specification("CustomSerializers Specification") with MongoTestKit {
+object CustomSerializersSpec extends Specification with MongoTestKit {
+ "CustomSerializers Specification".title
import customserializersspecs._
@@ -176,7 +177,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// retrieve it and compare
val mother2 = Person.find(mother.id)
- mother2 must notBeEmpty
+ mother2.isDefined must_== true
mother2 foreach {
m =>
m.children.value mustEqual mother.children.value
@@ -231,7 +232,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// retrieve it and compare
val mother2 = Person2.find(mother.id)
- mother2 must notBeEmpty
+ mother2.isDefined must_== true
mother2 foreach {
m =>
m.children.value mustEqual mother.children.value
@@ -288,7 +289,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// retrieve it and compare
val nfl2 = League.find(nfl.id)
- nfl2 must notBeEmpty
+ nfl2.isDefined must_== true
nfl2 foreach {
l =>
l.teams.value mustEqual nfl.teams.value
@@ -297,7 +298,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// find a player
val vqb = Player.find(vikes.qb)
- vqb must notBeEmpty
+ vqb.isDefined must_== true
vqb foreach {
p =>
p.name.value mustEqual "Brett Favre"
@@ -310,7 +311,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
val formPattern = <input name=".*" type="text" tabindex="1" value={nfl._id.value.toString} id="_id_id"></input>
S.initIfUninitted(session) {
val form = nfl._id.toForm
- form must notBeEmpty
+ form.isDefined must_== true
form foreach {
fprime =>
val f = ("* [name]" #> ".*" & "select *" #> (((ns: NodeSeq) => ns.filter {
@@ -359,7 +360,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// retrieve it and compare
val nfl2 = League2.find(nfl.id.toString)
- nfl2 must notBeEmpty
+ nfl2.isDefined must_== true
nfl2 foreach {
l =>
l.teams.value mustEqual nfl.teams.value
@@ -368,7 +369,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
// find a player
val vqb = Player.find(vikes.qb)
- vqb must notBeEmpty
+ vqb.isDefined must_== true
vqb foreach {
p =>
p.name.value mustEqual "Brett Favre"
@@ -381,7 +382,7 @@ object CustomSerializersSpec extends Specification("CustomSerializers Specificat
val formPattern = <input name=".*" type="text" tabindex="1" value={nfl._id.value.toString} id="_id_id"></input>
S.initIfUninitted(session) {
val form = nfl._id.toForm
- form must notBeEmpty
+ form.isDefined must_== true
form foreach {
fprime =>
val f = ("* [name]" #> ".*" & "select *" #> (((ns: NodeSeq) => ns.filter {
View
46 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoFieldSpec.scala
@@ -22,7 +22,9 @@ import java.util.{Date, UUID}
import java.util.regex.Pattern
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
+import org.specs2.specification.Fragment
+import org.specs2.specification.AroundExample
import common._
import json._
@@ -40,14 +42,16 @@ import Helpers._
/**
* Systems under specification for MongoField.
*/
-object MongoFieldSpec extends Specification("MongoField Specification") with MongoTestKit {
+object MongoFieldSpec extends Specification with MongoTestKit with AroundExample {
+ "MongoField Specification".title
+ sequential
+
import fixtures._
- val session = new LiftSession("", randomString(20), Empty)
- def inLiftSession(a: =>Any) = S.initIfUninitted(session) { a }
- new SpecContext {
- aroundExpectations(inLiftSession(_))
- }
+ lazy val session = new LiftSession("", randomString(20), Empty)
+
+ protected def around[T <% org.specs2.execute.Result](t: =>T) = S.initIfUninitted(session) { t }
+
def passBasicTests[A](
example: A,
mandatory: MandatoryTypedField[A],
@@ -58,8 +62,8 @@ object MongoFieldSpec extends Specification("MongoField Specification") with Mon
def commonBehaviorsForAllFlavors(field: MandatoryTypedField[A]) = {
"which have the correct initial value" in {
- field.value must beEqual(field.defaultValue).when(canCheckDefaultValues)
- field.valueBox must beEqual(field.defaultValueBox).when(canCheckDefaultValues)
+ field.value must be_==(field.defaultValue).when(canCheckDefaultValues)
+ field.valueBox must be_==(field.defaultValueBox).when(canCheckDefaultValues)
}
"which are readable and writable" in {
@@ -75,41 +79,38 @@ object MongoFieldSpec extends Specification("MongoField Specification") with Mon
}
"which correctly clear back to the default" in {
- { field.clear; field.valueBox } must beEqual(field.defaultValueBox).when(canCheckDefaultValues)
+ { field.clear; field.valueBox } must be_==(field.defaultValueBox).when(canCheckDefaultValues)
}
"which capture error conditions set in" in {
// FIXME: This needs to be rearranged just so that it doesn't foul with subsequent examples
// field.setBox(Failure("my failure"))
// Failure("my failure") must_== Failure("my failure")
+ pending
}
}
"support mandatory fields" in {
- setSequential()
-
"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
}
"common behaviors for all flavors" in {
commonBehaviorsForAllFlavors(mandatory)
}
"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 {
- setSequential()
-
"which are configured correctly" in {
legacyOptional.optional_? must_== true
}
@@ -139,11 +140,12 @@ object MongoFieldSpec extends Specification("MongoField Specification") with Mon
legacyOptional.value must_== legacyOptional.defaultValue
legacyOptional.valueBox must_== legacyOptional.defaultValueBox
}
+ success
}
}
}
- 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 {
@@ -160,17 +162,16 @@ object MongoFieldSpec extends Specification("MongoField Specification") with Mon
"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]]
}
}
- formPattern foreach { fp =>
- "convert to form XML" in {
+ "convert to form XML" in {
+ formPattern foreach { fp =>
mandatory.set(example)
val session = new LiftSession("", randomString(20), Empty)
S.initIfUninitted(session) {
val formXml = mandatory.toForm
- formXml must notBeEmpty
+ formXml.isDefined must_== true
formXml foreach { fprime =>
val f = ("* [name]" #> ".*" & "select *" #> (((ns: NodeSeq) => ns.filter {
case e: Elem => e.attribute("selected").map(_.text) == Some("selected")
@@ -182,6 +183,7 @@ object MongoFieldSpec extends Specification("MongoField Specification") with Mon
}
}
}
+ success
}
}
View
18 ...ce/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoRecordExamplesSpec.scala
@@ -28,7 +28,7 @@ import net.liftweb.json.JsonAST.JObject
import net.liftweb.record.field._
import net.liftweb.util.TimeHelpers._
-import org.specs.Specification
+import org.specs2.mutable.Specification
import com.mongodb._
import org.bson.types.ObjectId
@@ -237,7 +237,9 @@ package mongotestrecords {
/**
* Systems under specification for MongoRecordExamples.
*/
-object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specification") with MongoTestKit {
+class MongoRecordExamplesSpec extends Specification with MongoTestKit {
+ "MongoRecordExamples Specification".title
+
import mongotestrecords._
import net.liftweb.util.TimeHelpers._
@@ -305,6 +307,8 @@ object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specif
if (!debug) TstRecord.drop
}
+
+ success
}
"Ref example" in {
@@ -457,6 +461,8 @@ object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specif
RefDoc.drop
RefStringDoc.drop
}
+
+ success
}
"List example" in {
@@ -513,6 +519,8 @@ object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specif
ListDoc.drop
RefDoc.drop
}
+
+ success
}
"Map Example" in {
@@ -527,6 +535,8 @@ object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specif
md1.delete_!
if (!debug) MapDoc.drop
+
+ success
}
"Optional Example" in {
@@ -554,6 +564,8 @@ object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specif
}
if (!debug) OptionalDoc.drop
+
+ success
}
"Strict Example" in {
@@ -572,5 +584,7 @@ object MongoRecordExamplesSpec extends Specification("MongoRecordExamples Specif
sd2.save(true) must_== sd2
if (!debug) StrictDoc.drop
+
+ success
}
}
View
125 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoRecordSpec.scala
@@ -22,7 +22,8 @@ import java.util.{Date, Locale, UUID}
import java.util.regex.Pattern
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
+import org.specs2.specification.Fragment
import common._
import http.js.JsExp
@@ -37,13 +38,18 @@ import http.{S, LiftSession}
/**
* Systems under specification for MongoRecord.
*/
-object MongoRecordSpec extends Specification("MongoRecord Specification") with MongoTestKit {
+class MongoRecordSpec extends Specification with MongoTestKit {
+ "MongoRecord Specification".title
+
import fixtures._
val session = new LiftSession("hello", "", Empty)
- "MongoRecord field introspection" should {
+ override def before = {
+ super.before
checkMongoIsRunning
+ }
+ "MongoRecord field introspection" should {
val rec = MongoFieldTypeTestRecord.createRecord
val allExpectedFieldNames: List[String] = "_id" :: "mandatoryMongoCaseClassField" ::
(for {
@@ -56,22 +62,20 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"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
}
}
}
"MongoRecord lifecycle callbacks" should {
- checkMongoIsRunning
-
- 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
@@ -168,8 +172,6 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"MongoRecord" should {
- checkMongoIsRunning
-
val binData: Array[Byte] = Array(18, 19, 20)
val fttr = FieldTypeTestRecord.createRecord
@@ -334,16 +336,16 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
fttr.save
val fttrFromDb = FieldTypeTestRecord.find(fttr.id.value)
- fttrFromDb must notBeEmpty
+ fttrFromDb.isDefined must_== true
fttrFromDb foreach { tr =>
tr mustEqual fttr
}
bftr.save
val bftrFromDb = BinaryFieldTestRecord.find(bftr.id.value)
- bftrFromDb must notBeEmpty
- bftrFromDb foreach { tr =>
+ bftrFromDb.isDefined must_== true
+ bftrFromDb.toList map { tr =>
tr mustEqual bftr
}
}
@@ -354,56 +356,52 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
S.initIfUninitted(session) {
fttr.save
- FieldTypeTestRecord.find(fttr.id.value) must notBeEmpty
+ FieldTypeTestRecord.find(fttr.id.value).isDefined must_== true
fttr.delete_!
FieldTypeTestRecord.find(fttr.id.value) must beEmpty
}
}
"save and retrieve Mongo type fields with set values" in {
- checkMongoIsRunning
-
mfttr.save
val mfttrFromDb = MongoFieldTypeTestRecord.find(mfttr.id.value)
- mfttrFromDb must notBeEmpty
+ mfttrFromDb.isDefined must_== true
mfttrFromDb foreach { tr =>
tr mustEqual mfttr
}
ltr.save
val ltrFromDb = ListTestRecord.find(ltr.id.value)
- ltrFromDb must notBeEmpty
+ ltrFromDb.isDefined must_== true
ltrFromDb foreach { tr =>
tr mustEqual ltr
}
mtr.save
val mtrFromDb = MapTestRecord.find(mtr.id.value)
- mtrFromDb must notBeEmpty
+ mtrFromDb.isDefined must_== true
mtrFromDb foreach { tr =>
tr mustEqual mtr
}
srtr.save
val srtrFromDb = SubRecordTestRecord.find(srtr.id.value)
- srtrFromDb must notBeEmpty
- srtrFromDb foreach { tr =>
+ srtrFromDb.isDefined must_== true
+ srtrFromDb.toList map { tr =>
tr mustEqual srtr
}
}
"save and retrieve Mongo type fields with default values" in {
- checkMongoIsRunning
-
val mfttrDef = MongoFieldTypeTestRecord.createRecord
mfttrDef.save
val mfttrFromDb = MongoFieldTypeTestRecord.find(mfttrDef.id.value)
- mfttrFromDb must notBeEmpty
+ mfttrFromDb.isDefined must_== true
mfttrFromDb foreach { tr =>
tr mustEqual mfttrDef
}
@@ -412,7 +410,7 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
ltrDef.save
val ltrFromDb = ListTestRecord.find(ltrDef.id.value)
- ltrFromDb must notBeEmpty
+ ltrFromDb.isDefined must_== true
ltrFromDb foreach { tr =>
tr mustEqual ltrDef
}
@@ -421,7 +419,7 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
mtrDef.save
val mtrFromDb = MapTestRecord.find(mtrDef.id.value)
- mtrFromDb must notBeEmpty
+ mtrFromDb.isDefined must_== true
mtrFromDb foreach { tr =>
tr mustEqual mtrDef
}
@@ -430,15 +428,13 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
srtrDef.save
val srtrFromDb = SubRecordTestRecord.find(srtrDef.id.value)
- srtrFromDb must notBeEmpty
- srtrFromDb foreach { tr =>
+ srtrFromDb.isDefined must_== true
+ srtrFromDb.toList map { tr =>
tr mustEqual srtrDef
}
}
"convert Mongo type fields to JValue" in {
- checkMongoIsRunning
-
mfttr.asJValue mustEqual mfttrJson
ltr.asJValue mustEqual ltrJson
@@ -454,30 +450,26 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"get set from json string using lift-json parser" in {
- checkMongoIsRunning
-
val mfftrFromJson = MongoFieldTypeTestRecord.fromJsonString(compact(render(mfttrJson)))
- mfftrFromJson must notBeEmpty
+ mfftrFromJson.isDefined must_== true
mfftrFromJson foreach { tr =>
tr mustEqual mfttr
}
val ltrFromJson = ListTestRecord.fromJsonString(compact(render(ltrJson)))
- ltrFromJson must notBeEmpty
+ ltrFromJson.isDefined must_== true
ltrFromJson foreach { tr =>
tr mustEqual ltr
}
val mtrFromJson = MapTestRecord.fromJsonString(compact(render(mtrJson)))
- mtrFromJson must notBeEmpty
- mtrFromJson foreach { tr =>
+ mtrFromJson.isDefined must_== true
+ mtrFromJson.toList map { tr =>
tr mustEqual mtr
}
}
"handle null" in {
- checkMongoIsRunning
-
val ntr = NullTestRecord.createRecord
ntr.nullstring.set(null)
ntr.jsonobjlist.set(List(JsonObj("1", null), JsonObj("2", "jsonobj2")))
@@ -486,9 +478,9 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
val ntrFromDb = NullTestRecord.find(ntr.id.value)
- ntrFromDb must notBeEmpty
+ ntrFromDb.isDefined must_== true
- ntrFromDb foreach { n =>
+ ntrFromDb.toList map { n =>
// goes in as
ntr.nullstring.valueBox.map(_ must beNull)
ntr.nullstring.value must beNull
@@ -507,8 +499,6 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"handle Box using JsonBoxSerializer" in {
- checkMongoIsRunning
-
val btr = BoxTestRecord.createRecord
btr.jsonobjlist.set(
BoxTestJsonObj("1", Empty, Full("Full String1"), Failure("Failure1")) ::
@@ -520,9 +510,9 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
val btrFromDb = BoxTestRecord.find(btr.id.value)
- btrFromDb must notBeEmpty
+ btrFromDb.isDefined must_== true
- btrFromDb foreach { b =>
+ btrFromDb.toList map { b =>
b.jsonobjlist.value.size must_== 2
btr.jsonobjlist.value.size must_== 2
val sortedList = b.jsonobjlist.value.sortWith(_.id < _.id)
@@ -533,8 +523,6 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"retrieve MongoRef objects properly" in {
- checkMongoIsRunning
-
S.initIfUninitted(session) {
val ntr = NullTestRecord.createRecord
val btr = BoxTestRecord.createRecord
@@ -593,7 +581,6 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"use defaultValue when field is not present in the database" in {
- checkMongoIsRunning
S.initIfUninitted(session) {
val missingFieldDocId = ObjectId.get
@@ -605,9 +592,9 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
val recFromDb = FieldTypeTestRecord.find(missingFieldDocId)
- recFromDb must notBeEmpty
+ recFromDb.isDefined must_== true
- recFromDb foreach { r =>
+ recFromDb.toList map { r =>
r.mandatoryBooleanField.is must_== false
r.legacyOptionalBooleanField
r.optionalBooleanField.is must beEmpty
@@ -652,8 +639,6 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"reset dirty flags on save" in {
- checkMongoIsRunning
-
val fttr = FieldTypeTestRecord.createRecord.save
fttr.mandatoryDecimalField(BigDecimal("3.14"))
fttr.dirtyFields.length must_== 1
@@ -662,8 +647,6 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
}
"update dirty fields for a FieldTypeTestRecord" in {
- checkMongoIsRunning
-
S.initIfUninitted(session) {
val fttr = FieldTypeTestRecord.createRecord
.legacyOptionalStringField("legacy optional string")
@@ -702,7 +685,7 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
fttr.dirtyFields.length must_== 0
val fromDb = FieldTypeTestRecord.find(fttr.id.is)
- fromDb must notBeEmpty
+ fromDb.isDefined must_== true
fromDb foreach { rec =>
rec must_== fttr
rec.dirtyFields.length must_== 0
@@ -722,17 +705,15 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
fttr2.dirtyFields.length must_== 0
val fromDb2 = FieldTypeTestRecord.find(fttr2.id.is)
- fromDb2 must notBeEmpty
- fromDb2 foreach { rec =>
+ fromDb2.isDefined must_== true
+ fromDb2.toList map { rec =>
rec must_== fttr2
rec.dirtyFields.length must_== 0
}
}
}
"update dirty fields for a MongoFieldTypeTestRecord" in {
- checkMongoIsRunning
-
val mfttr = MongoFieldTypeTestRecord.createRecord
.legacyOptionalDateField(new Date)
.legacyOptionalObjectIdField(ObjectId.get)
@@ -766,7 +747,7 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
mfttr.dirtyFields.length must_== 0
val fromDb = MongoFieldTypeTestRecord.find(mfttr.id.is)
- fromDb must notBeEmpty
+ fromDb.isDefined must_== true
fromDb foreach { rec =>
rec must_== mfttr
rec.dirtyFields.length must_== 0
@@ -785,16 +766,14 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
mfttr2.dirtyFields.length must_== 0
val fromDb2 = MongoFieldTypeTestRecord.find(mfttr2.id.is)
- fromDb2 must notBeEmpty
- fromDb2 foreach { rec =>
+ fromDb2.isDefined must_== true
+ fromDb2.toList map { rec =>
rec must_== mfttr2
rec.dirtyFields.length must_== 0
}
}
"update dirty fields for a ListTestRecord" in {
- checkMongoIsRunning
-
val ltr = ListTestRecord.createRecord.save
ltr.mandatoryStringListField(List("abc", "def", "ghi"))
@@ -814,16 +793,14 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
ltr.dirtyFields.length must_== 0
val fromDb = ListTestRecord.find(ltr.id.is)
- fromDb must notBeEmpty
- fromDb foreach { rec =>
+ fromDb.isDefined must_== true
+ fromDb.toList map { rec =>
rec must_== ltr
rec.dirtyFields.length must_== 0
}
}
"update dirty fields for a MapTestRecord" in {
- checkMongoIsRunning
-
val mtr = MapTestRecord.save
mtr.mandatoryStringMapField(Map("a" -> "abc", "b" -> "def", "c" -> "ghi"))
@@ -837,16 +814,14 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
mtr.dirtyFields.length must_== 0
val fromDb = MapTestRecord.find(mtr.id.is)
- fromDb must notBeEmpty
- fromDb foreach { rec =>
+ fromDb.isDefined must_== true
+ fromDb.toList map { rec =>
rec must_== mtr
rec.dirtyFields.length must_== 0
}
}
"update dirty fields for a SubRecordTestRecord" in {
- checkMongoIsRunning
-
val srtr = SubRecordTestRecord.createRecord.save
val ssr1 = SubSubRecord.createRecord.name("SubSubRecord1")
@@ -873,8 +848,8 @@ object MongoRecordSpec extends Specification("MongoRecord Specification") with M
srtr.dirtyFields.length must_== 0
val fromDb = SubRecordTestRecord.find(srtr.id.is)
- fromDb must notBeEmpty
- fromDb foreach { rec =>
+ fromDb.isDefined must_== true
+ fromDb.toList map { rec =>
rec must_== srtr
rec.dirtyFields.length must_== 0
}
View
21 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/MongoTestKit.scala
@@ -14,16 +14,17 @@
* limitations under the License.
*/
-package net.liftweb
-package mongodb
-package record
+package net.liftweb
+package mongodb
+package record
-import org.specs.Specification
+import org.specs2.mutable.Specification
+import org.specs2.specification.BeforeAfterExample
import com.mongodb._
-trait MongoTestKit {
- this: Specification =>
+trait MongoTestKit extends Specification with BeforeAfterExample {
+ sequential
def dbName = "lift_record_"+this.getClass.getName
.replace("$", "")
@@ -34,12 +35,12 @@ trait MongoTestKit {
val defaultHost = MongoHost("127.0.0.1", 27017)
// If you need more than one db, override this
- def dbs: List[(MongoIdentifier, MongoHost, String)] =
+ def dbs: List[(MongoIdentifier, MongoHost, String)] =
List((DefaultMongoIdentifier, defaultHost, dbName))
def debug = false
- doBeforeSpec {
+ def before = {
// define the dbs
dbs foreach { dbtuple =>
MongoDB.defineDb(dbtuple._1, MongoAddress(dbtuple._2, dbtuple._3))
@@ -61,9 +62,9 @@ trait MongoTestKit {
}
def checkMongoIsRunning =
- isMongoRunning must beEqualTo(true).orSkipExample
+ isMongoRunning must beEqualTo(true).orSkip
- doAfterSpec {
+ def after = {
if (!debug && isMongoRunning) {
// drop the databases
dbs foreach { dbtuple =>
View
6 persistence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/QueryExamplesSpec.scala
@@ -27,7 +27,7 @@ import java.util.{Calendar, Date, UUID}
import java.util.regex.Pattern
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
package queryexamplesfixtures {
class Person private () extends MongoRecord[Person] with ObjectIdPk[Person] {
@@ -49,7 +49,9 @@ package queryexamplesfixtures {
}
}
-object QueryExamplesSpec extends Specification("QueryExamples Specification") with MongoTestKit {
+object QueryExamplesSpec extends Specification with MongoTestKit {
+ "QueryExamples Specification".title
+
import queryexamplesfixtures._
"Query examples" in {
View
21 ...stence/mongodb-record/src/test/scala/net/liftweb/mongodb/record/field/EnumFieldSpec.scala
@@ -20,7 +20,7 @@ package record
package field
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
import net.liftweb.common._
import net.liftweb.json.ext.EnumSerializer
@@ -68,7 +68,8 @@ package enumfieldspecs {
/**
* Systems under specification for EnumField.
*/
-object EnumFieldSpec extends Specification("EnumField Specification") with MongoTestKit {
+class EnumFieldSpec extends Specification with MongoTestKit {
+ "EnumField Specification".title
import enumfieldspecs._
@@ -80,8 +81,8 @@ object EnumFieldSpec extends Specification("EnumField Specification") with Mongo
val er = EnumRec.createRecord.save
val erFromDb = EnumRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dow.value mustEqual WeekDay.Mon
er2.dowOptional.valueBox mustEqual Empty
@@ -98,8 +99,8 @@ object EnumFieldSpec extends Specification("EnumField Specification") with Mongo
.save
val erFromDb = EnumRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dow.value mustEqual WeekDay.Tue
er2.jsonobj.value mustEqual JsonObj(WeekDay.Sun)
@@ -114,8 +115,8 @@ object EnumFieldSpec extends Specification("EnumField Specification") with Mongo
er.save
val erFromDb = EnumRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dowOptional.valueBox mustEqual Empty
}
@@ -129,8 +130,8 @@ object EnumFieldSpec extends Specification("EnumField Specification") with Mongo
er.save
val erFromDb = EnumRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dowOptional.valueBox mustEqual Full(WeekDay.Sat)
}
View
23 ...ce/mongodb-record/src/test/scala/net/liftweb/mongodb/record/field/EnumNameFieldSpec.scala
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 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.
@@ -20,7 +20,7 @@ package record
package field
import org.bson.types.ObjectId
-import org.specs.Specification
+import org.specs2.mutable.Specification
import net.liftweb.common._
import net.liftweb.json.ext.EnumNameSerializer
@@ -68,7 +68,8 @@ package enumnamefieldspecs {
/**
* Systems under specification for EnumNameField.
*/
-object EnumNameFieldSpec extends Specification("EnumNameField Specification") with MongoTestKit {
+object EnumNameFieldSpec extends Specification with MongoTestKit {
+ "EnumNameField Specification".title
import enumnamefieldspecs._
@@ -80,8 +81,8 @@ object EnumNameFieldSpec extends Specification("EnumNameField Specification") wi
val er = EnumNameRec.createRecord.save
val erFromDb = EnumNameRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dow.value mustEqual WeekDay.Mon
er2.dowOptional.valueBox mustEqual Empty
@@ -98,8 +99,8 @@ object EnumNameFieldSpec extends Specification("EnumNameField Specification") wi
.save
val erFromDb = EnumNameRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dow.value mustEqual WeekDay.Tue
er2.jsonobj.value mustEqual JsonObj(WeekDay.Sun)
@@ -114,8 +115,8 @@ object EnumNameFieldSpec extends Specification("EnumNameField Specification") wi
er.save
val erFromDb = EnumNameRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dowOptional.valueBox mustEqual Empty
}
@@ -129,8 +130,8 @@ object EnumNameFieldSpec extends Specification("EnumNameField Specification") wi
er.save
val erFromDb = EnumNameRec.find(er.id)
- erFromDb must notBeEmpty
- erFromDb foreach { er2 =>
+ erFromDb.isDefined must_== true
+ erFromDb.toList map { er2 =>
er2 mustEqual er
er2.dowOptional.valueBox mustEqual Full(WeekDay.Sat)
}

1 comment on commit d9dacce

@fmpwizard
Lift Web Framework member

+1

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