progress on user db and testing
This commit is contained in:
parent
019dc78a27
commit
5ed4603fe8
|
@ -89,7 +89,7 @@ abstract class Coll[Doc <: WithStringId](db: LilaDB, name: String, json: JsonTub
|
|||
|
||||
private implicit val bsonReads = new BSONReader[Option[Doc]] {
|
||||
def fromBSON(bson: BSONDocument): Option[Doc] =
|
||||
json.read(JsObjectReader fromBSON bson.pp).asOpt
|
||||
json.fromMongo(JsObjectReader fromBSON bson).asOpt
|
||||
}
|
||||
|
||||
private val coll = db(name)
|
||||
|
|
|
@ -16,14 +16,14 @@ case class JsonTube[Doc](reads: Reads[Doc], writes: Writes[Doc]) {
|
|||
|
||||
def toMongo(doc: Doc): JsResult[JsValue] = JsonTube toMongo write(doc)
|
||||
|
||||
def fromMongo(js: JsObject): JsResult[Doc] = JsonTube fromMongo js flatMap read
|
||||
def fromMongo(js: JsObject): JsResult[Doc] = (JsonTube fromMongo js).pp flatMap read
|
||||
}
|
||||
|
||||
object JsonTube {
|
||||
|
||||
val toMongoTransformer = rename('_id, 'id)
|
||||
val toMongoTransformer = rename('id, '_id)
|
||||
|
||||
val fromMongoTransformer = rename('id, '_id)
|
||||
val fromMongoTransformer = rename('_id, 'id)
|
||||
|
||||
private def rename(from: Symbol, to: Symbol) = __.json update (
|
||||
(__ \ to).json copyFrom (__ \ from).json.pick
|
||||
|
|
|
@ -40,6 +40,7 @@ trait Dependencies {
|
|||
val reactivemongo = "org.reactivemongo" %% "reactivemongo" % "0.8"
|
||||
val playReactivemongo = "play.modules.reactivemongo" %% "play2-reactivemongo" % "0.1-SNAPSHOT" cross CrossVersion.full
|
||||
val playProvided = "play" %% "play" % "2.1-SNAPSHOT" % "provided"
|
||||
val playTestProvided = "play" %% "play-test" % "2.1-SNAPSHOT" % "provided"
|
||||
val sprayCaching = "io.spray" % "spray-caching" % "1.1-M7"
|
||||
}
|
||||
|
||||
|
@ -50,7 +51,7 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
scalaVersion in ThisBuild := "2.10.0",
|
||||
resolvers in ThisBuild ++= Seq(
|
||||
awesomepom, iliaz, sonatype, sonatypeS, // sgodbillon,
|
||||
typesafe, t2v, jgitMaven, christophs),
|
||||
typesafe, t2v, jgitMaven, christophs, spray),
|
||||
scalacOptions := Seq(
|
||||
"-deprecation",
|
||||
"-unchecked",
|
||||
|
@ -77,7 +78,7 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
lazy val common = project("common").settings(
|
||||
libraryDependencies := Seq(scalaz, scalalib, jodaTime, jodaConvert, playProvided, reactivemongo)
|
||||
)
|
||||
|
||||
|
||||
lazy val memo = project("memo", Seq(common)).settings(
|
||||
libraryDependencies := Seq(scalaz, scalalib, guava, findbugs)
|
||||
)
|
||||
|
@ -92,8 +93,9 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
lazy val user = project("user", Seq(scalachess, common, memo, db)).settings(
|
||||
libraryDependencies := Seq(
|
||||
scalaz, scalalib, jodaTime, jodaConvert, playProvided, salat,
|
||||
paginator, paginatorSalat, sprayCaching),
|
||||
resolvers += spray
|
||||
paginator, paginatorSalat, sprayCaching, playTestProvided),
|
||||
scalaSource in Compile <<= (sourceDirectory in Compile)(identity),
|
||||
scalaSource in Test <<= (sourceDirectory in Test)(identity)
|
||||
)
|
||||
|
||||
lazy val scalachess = project("scalachess").settings(
|
||||
|
@ -101,5 +103,7 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
)
|
||||
|
||||
private def project(name: String, deps: Seq[sbt.ClasspathDep[sbt.ProjectReference]] = Seq.empty) =
|
||||
Project(name, file(name), settings = buildSettings, dependencies = deps)
|
||||
Project(name, file(name), dependencies = deps, settings = buildSettings ++ Seq(
|
||||
// scalaSource in Compile <<= (sourceDirectory in Compile)(identity)
|
||||
))
|
||||
}
|
||||
|
|
45
user/src/test/RepoTest.scala
Normal file
45
user/src/test/RepoTest.scala
Normal file
|
@ -0,0 +1,45 @@
|
|||
package lila.user
|
||||
|
||||
import org.specs2.mutable._
|
||||
|
||||
import play.api.test._
|
||||
import play.api.test.Helpers._
|
||||
|
||||
import scala.concurrent.Await
|
||||
|
||||
object Common {
|
||||
import scala.concurrent._
|
||||
import scala.concurrent.duration._
|
||||
import reactivemongo.api._
|
||||
import reactivemongo.bson.handlers.DefaultBSONHandlers
|
||||
|
||||
implicit val ec = ExecutionContext.Implicits.global
|
||||
implicit val writer = DefaultBSONHandlers.DefaultBSONDocumentWriter
|
||||
implicit val reader = DefaultBSONHandlers.DefaultBSONDocumentReader
|
||||
implicit val handler = DefaultBSONHandlers.DefaultBSONReaderHandler
|
||||
|
||||
val timeout = 2 seconds
|
||||
|
||||
lazy val connection = MongoConnection(List("localhost:27017"))
|
||||
lazy val db = {
|
||||
val _db = connection("lichess")
|
||||
// Await.ready(_db.drop, timeout)
|
||||
_db
|
||||
}
|
||||
}
|
||||
|
||||
class RepoTest extends Specification {
|
||||
|
||||
import Common._
|
||||
|
||||
val repo = new UserRepo(db, "user2")
|
||||
|
||||
"The user repo" should {
|
||||
"find users" in {
|
||||
Await.result(repo.find(repo.query.q, 2), timeout) must haveSize(2)
|
||||
}
|
||||
// "find thibault" in {
|
||||
// Await.result(repo byId "thibault", timeout) must beSome
|
||||
// }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue