Add game repo tests and implementation
This commit is contained in:
parent
231553acff
commit
825a583b98
17
system/src/main/scala/GameRepo.scala
Normal file
17
system/src/main/scala/GameRepo.scala
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package lila.system
|
||||||
|
package repo
|
||||||
|
|
||||||
|
import model._
|
||||||
|
|
||||||
|
import com.novus.salat._
|
||||||
|
import com.novus.salat.global._
|
||||||
|
import com.novus.salat.dao._
|
||||||
|
import com.mongodb.casbah.MongoCollection
|
||||||
|
import com.mongodb.casbah.Imports._
|
||||||
|
|
||||||
|
class GameRepo(collection: MongoCollection) extends SalatDAO[Game, String](collection) {
|
||||||
|
|
||||||
|
def game(id: String): Option[Game] = findOneByID(id)
|
||||||
|
|
||||||
|
def anyGame = findOne(DBObject())
|
||||||
|
}
|
23
system/src/test/scala/GameRepoTest.scala
Normal file
23
system/src/test/scala/GameRepoTest.scala
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package lila.system
|
||||||
|
|
||||||
|
class GameRepoTest extends SystemTest {
|
||||||
|
|
||||||
|
val env = SystemEnv()
|
||||||
|
val repo = env.gameRepo
|
||||||
|
val anyGame = repo.anyGame.get
|
||||||
|
|
||||||
|
"the game repo" should {
|
||||||
|
"find a game" in {
|
||||||
|
"by ID" in {
|
||||||
|
"non existing" in {
|
||||||
|
repo game "haha" must beNone
|
||||||
|
}
|
||||||
|
"existing" in {
|
||||||
|
repo game anyGame.id must beSome.like {
|
||||||
|
case g ⇒ g.id must_== anyGame.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue