Permalink
Browse files

lift-db, lift-mapper

  • Loading branch information...
1 parent ea1c868 commit 0b20cc8d55a21525aa6e8967b3636dfc38e474f4 @nafg nafg committed Jul 31, 2012
@@ -17,8 +17,8 @@
package net.liftweb
package db
-import org.specs.Specification
-import org.specs.mock.Mockito
+import org.specs2.mutable.Specification
+import org.specs2.mock.Mockito
import org.mockito.Matchers._
import net.liftweb.common._
@@ -28,6 +28,8 @@ import net.liftweb.util.ControlHelpers._
import java.sql._
class DBSpec extends Specification with Mockito {
+ sequential
+
trait CommitFunc {
def f(success: Boolean): Unit
}
@@ -142,6 +144,7 @@ class DBSpec extends Specification with Mockito {
there was one(activeConnection).rollback
there was one(m).f(false)
+ success
}
}
@@ -17,7 +17,7 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
import util._
@@ -27,7 +27,9 @@ import http.{S, LiftSession}
/**
* Systems under specification for DB.
*/
-object DbSpec extends Specification("DB Specification") {
+object DbSpec extends Specification {
+ "DB Specification".title
+
val provider = DbProviders.H2MemoryProvider
val logF = Schemifier.infoF _
@@ -17,7 +17,7 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
import json._
@@ -29,7 +29,9 @@ import view._
/**
* Systems under specification for ItemsList.
*/
-object ItemsListSpec extends Specification("ItemsList Specification") {
+object ItemsListSpec extends Specification {
+ "ItemsList Specification".title
+ sequential
val provider = DbProviders.H2MemoryProvider
@@ -17,15 +17,17 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
/**
* Systems under specification for ManyToMany.
*/
-object ManyToManySpec extends Specification("ManyToMany Specification") {
+object ManyToManySpec extends Specification {
+ "ManyToMany Specification".title
+ sequential
val provider = DbProviders.H2MemoryProvider
-
+
private def ignoreLogger(f: => AnyRef): Unit = ()
def setupDB {
MapperRules.createForeignKeys_? = c => false
@@ -17,15 +17,18 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
/**
* Systems under specification for MappedDate.
*/
-object MappedBooleanSpec extends Specification("MappedBoolean Specification") {
+object MappedBooleanSpec extends Specification {
+ "MappedBoolean Specification".title
+ sequential
+
val provider = DbProviders.H2MemoryProvider
private def ignoreLogger(f: => AnyRef): Unit = ()
@@ -17,15 +17,17 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
/**
* Systems under specification for MappedDate.
*/
-object MappedDateSpec extends Specification("MappedDate Specification") {
+object MappedDateSpec extends Specification {
+ "MappedDate Specification".title
+
"MappedDate" should {
"handle a Number in setFromAny" in {
val dog = Dog2.create
@@ -17,17 +17,20 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
/**
* Systems under specification for MappedDate.
*/
-object MappedDecimalSpec extends Specification("MappedDecimal Specification") {
+object MappedDecimalSpec extends Specification {
+ "MappedDecimal Specification".title
+ sequential
+
val provider = DbProviders.H2MemoryProvider
-
+
private def ignoreLogger(f: => AnyRef): Unit = ()
def setupDB {
provider.setupDB
@@ -17,7 +17,7 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
@@ -37,10 +37,11 @@ class EnumObj extends LongKeyedMapper[EnumObj] with IdPK {
object EnumObj extends EnumObj with LongKeyedMetaMapper[EnumObj]
-object MappedEnumSpec extends Specification("MappedEnum Specification") {
+object MappedEnumSpec extends Specification {
+ "MappedEnum Specification".title
+
"MappedEnum" should {
"preserve enumeration order when building display list" in {
- skip("Will not work with Scala 2.8.1 https://issues.scala-lang.org/browse/SI-3687")
val v = EnumObj.create
import MyEnum._
@@ -17,7 +17,7 @@
package net.liftweb
package mapper
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
import util._
@@ -26,21 +26,23 @@ import util._
/**
* Systems under specification for MappedLongForeignKey.
*/
-object MappedLongForeignKeySpec extends Specification("MappedLongForeignKey Specification") {
+object MappedLongForeignKeySpec extends Specification with org.specs2.specification.BeforeExample {
+ "MappedLongForeignKey Specification".title
+ sequential
+
// Make sure we have everything configured first
MapperSpecsModel.setup()
def provider = DbProviders.H2MemoryProvider
+ def before = MapperSpecsModel.cleanup()
+
"MappedLongForeignKey" should {
- doBefore {
(try {
provider.setupDB
- MapperSpecsModel.cleanup()
} catch {
- case e if !provider.required_? => skip("Provider %s not available: %s".format(provider, e))
- }) must not(throwAnException[Exception]).orSkipExample
- }
+ case e if !provider.required_? => 1 must be_==(2).orSkip("Provider %s not available: %s".format(provider, e))
+ }) must not(throwA[Exception]).orSkip
"Not allow comparison to another FK" in {
val dog = Dog.create.name("Froo").saveMe
@@ -79,8 +81,8 @@ object MappedLongForeignKeySpec extends Specification("MappedLongForeignKey Spec
val dog = Dog.create.owner(user)
dog.owner(Empty)
- dog.owner.obj mustBe Empty
- dog.owner.is mustBe 0L
+ dog.owner.obj must_== Empty
+ dog.owner.is must_== 0L
}
}
}
@@ -19,7 +19,8 @@ package mapper
import java.util.Locale
-import org.specs.Specification
+import org.specs2.mutable.Specification
+import org.specs2.specification.BeforeExample
import common._
import json._
@@ -33,9 +34,10 @@ import http.provider.HTTPRequest
* Systems under specification for Mapper. The model classes here are
* defined in MapperSpecsModel.scala
*/
-object MapperSpec extends Specification("Mapper Specification") {
+class MapperSpec extends Specification with BeforeExample {
+ "Mapper Specification".title
// Do everything in order.
- setSequential()
+ sequential
// Make sure we have everything configured first
MapperSpecsModel.setup()
@@ -56,19 +58,14 @@ object MapperSpec extends Specification("Mapper Specification") {
// if (!DB.loggingEnabled_? && doLog) DB.addLogFunc(logDBStuff)
+ def before = MapperSpecsModel.cleanup() // before each example
+
providers.foreach(provider => {
+ try {
+ provider.setupDB
("Mapper for " + provider.name) should {
- doBefore {
- (try {
- provider.setupDB
- MapperSpecsModel.cleanup()
- } catch {
- case e if !provider.required_? => skip("Provider %s not available: %s".format(provider, e))
- }) must not(throwAnException[Exception]).orSkipExample
- }
-
"schemify" in {
val elwood = SampleModel.find(By(SampleModel.firstName, "Elwood")).open_!
val madeline = SampleModel.find(By(SampleModel.firstName, "Madeline")).open_!
@@ -106,6 +103,7 @@ object MapperSpec extends Specification("Mapper Specification") {
SampleModel.firstName.displayName must_== "da_DK:SampleModel.firstName"
LiftRules.localeCalculator = localeCalculator
+ success
}
"snake connection should snakify default table & column names" in {
@@ -176,7 +174,7 @@ object MapperSpec extends Specification("Mapper Specification") {
for (t <- mm)
(t.tag.is.startsWith("M")) must beTrue
- for (t <- mm) {
+ for (t <- mm) yield {
t.model.cached_? must beFalse
t.model.obj
t.model.cached_? must beTrue
@@ -199,8 +197,8 @@ object MapperSpec extends Specification("Mapper Specification") {
"enforce FK constraint on DefaultConnection" in {
val supportsFK = DB.use(DefaultConnectionIdentifier) { conn => conn.driverType.supportsForeignKeys_? }
- if (!supportsFK) skip("Driver %s does not support FK constraints".format(provider))
-
+ if (!supportsFK) skipped("Driver %s does not support FK constraints".format(provider))
+
SampleTag.create.model(42).save must throwA[java.sql.SQLException]
}
@@ -212,7 +210,7 @@ object MapperSpec extends Specification("Mapper Specification") {
val oo = SampleTag.findAll(By(SampleTag.tag, "Meow"), PreCache(SampleTag.model))
(oo.length > 0) must beTrue
- for (t <- oo) t.model.cached_? must beTrue
+ for (t <- oo) yield t.model.cached_? must beTrue
}
"Precache works with OrderBy" in {
@@ -227,22 +225,23 @@ object MapperSpec extends Specification("Mapper Specification") {
(oo.length > 0) must beTrue
for (t <- oo) t.model.cached_? must beTrue
}
+ success
}
"Non-deterministic Precache works" in {
val dogs = Dog.findAll(By(Dog.name, "fido"), PreCache(Dog.owner, false))
val oo = SampleTag.findAll(By(SampleTag.tag, "Meow"), PreCache(SampleTag.model, false))
(oo.length > 0) must beTrue
- for (t <- oo) t.model.cached_? must beTrue
+ for (t <- oo) yield t.model.cached_? must beTrue
}
"Non-deterministic Precache works with OrderBy" in {
val dogs = Dog.findAll(By(Dog.name, "fido"), OrderBy(Dog.name, Ascending), PreCache(Dog.owner, false))
val oo = SampleTag.findAll(OrderBy(SampleTag.tag, Ascending), MaxRows(2), PreCache(SampleTag.model, false))
(oo.length > 0) must beTrue
- for (t <- oo) t.model.cached_? must beTrue
+ for (t <- oo) yield t.model.cached_? must beTrue
}
"work with Mixed case" in {
@@ -316,20 +315,21 @@ object MapperSpec extends Specification("Mapper Specification") {
val oo = SampleTag.findAll(OrderBy(SampleTag.tag, Ascending), MaxRows(2), PreCache(SampleTag.model))
(oo.length > 0) must beTrue
- for (t <- oo) t.model.cached_? must beTrue
+ for (t <- oo) yield t.model.cached_? must beTrue
}
+ success
}
"Non-deterministic Precache works with Mixed Case" in {
val dogs = Dog2.findAll(By(Dog2.name, "fido"), PreCache(Dog2.owner, false))
val oo = SampleTag.findAll(By(SampleTag.tag, "Meow"), PreCache(SampleTag.model, false))
(oo.length > 0) must beTrue
- for (t <- oo) t.model.cached_? must beTrue
+ for (t <- oo) yield t.model.cached_? must beTrue
}
- "Createdat and updated at work" in {
+ "CreatedAt and UpdatedAt work" in {
val now = Helpers.now
val dog = Dog2.find().open_!
@@ -355,10 +355,10 @@ object MapperSpec extends Specification("Mapper Specification") {
val oo = SampleTag.findAll(OrderBy(SampleTag.tag, Ascending), MaxRows(2), PreCache(SampleTag.model, false))
(oo.length > 0) must beTrue
- for (t <- oo) t.model.cached_? must beTrue
+ for (t <- oo) yield t.model.cached_? must beTrue
}
- "Save flag works" in {
+ "Save flag results in update rather than insert" in {
val elwood = SampleModel.find(By(SampleModel.firstName, "Elwood")).open_!
elwood.firstName.is must_== "Elwood"
elwood.firstName("Frog").save
@@ -377,6 +377,10 @@ object MapperSpec extends Specification("Mapper Specification") {
result.length must_== 2
}
}
+ } catch {
+ case e if !provider.required_? => skipped("Provider %s not available: %s".format(provider, e))
+ case _ => skipped
+ }
})
}
@@ -17,9 +17,11 @@
package net.liftweb {
package mapper {
-import org.specs.Specification
+import org.specs2.mutable.Specification
-object OneToManySpecs extends Specification("One to Many Specification") {
+object OneToManySpecs extends Specification {
+ "One to Many Specification".title
+ sequential
val provider = DbProviders.H2MemoryProvider
Oops, something went wrong.

1 comment on commit 0b20cc8

Owner

fmpwizard commented on 0b20cc8 Aug 20, 2012

+1

Please sign in to comment.