Last active
August 29, 2015 14:09
-
-
Save iref/2b6586b5bb9d5400471b to your computer and use it in GitHub Desktop.
Implicits session is not found in passed anonymous function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
import org.specs2.mutable.Specification | |
import play.api.Play.current | |
import play.api.db.slick.{DB, Session} | |
import play.api.db.slick.Config.driver.simple._ | |
import play.api.test.FakeApplication | |
import play.api.test.Helpers._ | |
class UserSpec extends Specification { | |
"UserRepository" should { | |
"save new user" in { | |
withDatabase { | |
val user = User("Octocat", "[email protected]") | |
val savedUser = Users.save(user) | |
val foundUser = Users.find(savedUser.id.get).get | |
foundUser.name must beEqualTo("Octocat") | |
foundUser.email must beEqualTo("[email protected]") | |
} | |
} | |
} | |
def withDatabase[T](test: => T): T = | |
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) { | |
DB.withSession { implicit session: Session => | |
test | |
} | |
} | |
} |
If I wrap test directly in DB.withSession, e.g.
"save new user" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
DB.withSession { implicit session: Session =>
val user = User("Octocat", "[email protected]")
val savedUser = Users.save(user)
val foundUser = Users.find(savedUser.id.get).get
foundUser.name must beEqualTo("Octocat")
foundUser.email must beEqualTo("[email protected]")
}
}
}
Spec file is compiled without any problems.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scala can't resolve implicit session for Users.save if its in passed block.
Compilation error is