Skip to content

Instantly share code, notes, and snippets.

@mediavrog
Created April 16, 2015 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mediavrog/a3c1bc9e23a2032121f9 to your computer and use it in GitHub Desktop.
Save mediavrog/a3c1bc9e23a2032121f9 to your computer and use it in GitHub Desktop.
import com.github.aselab.activerecord.{PlayConfig, ActiveRecordTables}
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
import play.api.Play
import play.api.test.FakeApplication
trait ActiveRecordAutoRollback extends BeforeAndAfterEach with BeforeAndAfterAll {
self: ApiBaseSpec =>
def schema: Seq[ActiveRecordTables] = Seq(ActiveRecordTables.find("models.Tables"))
override def beforeAll = {
Play.start(FakeApplication(additionalConfiguration = app.additionalConfiguration))
System.setProperty("run.mode", "test")
schema.foreach(_.initialize(Map()))
}
override def afterAll = {
schema.foreach { s => s.transaction {
s.drop
s.cleanup
}
}
Play.stop()
}
override def beforeEach = {
self.schema.foreach(_.startTransaction)
}
override def afterEach = {
self.schema.reverse.foreach(_.rollback)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment