Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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