This file contains 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
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