diff --git a/system/src/main/scala/GameRepo.scala b/system/src/main/scala/GameRepo.scala new file mode 100644 index 0000000000..61e59e8231 --- /dev/null +++ b/system/src/main/scala/GameRepo.scala @@ -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()) +} diff --git a/system/src/test/scala/GameRepoTest.scala b/system/src/test/scala/GameRepoTest.scala new file mode 100644 index 0000000000..13a82030f6 --- /dev/null +++ b/system/src/test/scala/GameRepoTest.scala @@ -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 + } + } + } + } + } +}