Skip to content

Commit

Permalink
Huzzah! Tests pass!!
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydmeta committed Jul 3, 2017
1 parent 4bf01b4 commit 816d8bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 44 deletions.
5 changes: 4 additions & 1 deletion test/com/m3/octoparts/support/db/DBSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import org.scalatest.{ Status, Args, BeforeAndAfterAll, fixture }
trait DBSuite extends AutoRollback2 with BeforeAndAfterAll with PlayAppSupport { this: fixture.Suite =>

override def beforeAll(): Unit = {
tearDown()
migrate()
}

override def afterAll(): Unit = {
tearDown()
}

/*
* No-op abstract override to resolve multiple definitions of run in extended traits
*/
Expand Down
49 changes: 6 additions & 43 deletions test/com/m3/octoparts/support/db/RequiresDB.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.m3.octoparts.support.db

import java.sql.Connection

import com.beachape.logging.LTSVLogger
import org.flywaydb.core.Flyway
import org.flywaydb.core.api.MigrationInfo
import org.flywaydb.core.api.callback.FlywayCallback
import org.scalatest.Suite
import scalikejdbc.ConnectionPool

Expand All @@ -21,41 +17,8 @@ import scala.util.control.NonFatal
*/
private[support] trait RequiresDB extends Suite {

lazy val flyway = {
def flyway = {
val flyway = new Flyway
flyway.setCallbacks(new FlywayCallback {
def beforeInit(conn: Connection) = conn.setReadOnly(false)

def beforeRepair(conn: Connection) = conn.setReadOnly(false)

def beforeValidate(conn: Connection) = conn.setReadOnly(false)

def beforeInfo(conn: Connection) = conn.setReadOnly(false)

def beforeClean(conn: Connection) = conn.setReadOnly(false)

def beforeMigrate(conn: Connection) = conn.setReadOnly(false)

def beforeBaseline(conn: Connection) = conn.setReadOnly(false)

def beforeEachMigrate(conn: Connection, p2: MigrationInfo) = conn.setReadOnly(false)

def afterInfo(conn: Connection) = conn.setReadOnly(false)

def afterInit(conn: Connection) = conn.setReadOnly(false)

def afterRepair(conn: Connection) = conn.setReadOnly(false)

def afterValidate(conn: Connection) = conn.setReadOnly(false)

def afterEachMigrate(conn: Connection, p2: MigrationInfo) = conn.setReadOnly(false)

def afterMigrate(conn: Connection) = conn.setReadOnly(false)

def afterClean(conn: Connection) = conn.setReadOnly(false)

def afterBaseline(conn: Connection) = conn.setReadOnly(false)
})
flyway.setDataSource(ConnectionPool().dataSource)
flyway.setPlaceholderPrefix("$flyway{")
flyway
Expand All @@ -70,12 +33,12 @@ private[support] trait RequiresDB extends Suite {
def tearDown(): Unit = {
try {
/*
Tries to drop all objects in the database.
Tries to drop all objects in the database.
Needs to be in this try because it throws the database doesn't have the schema_version
table, which may happen if in an arbitrary test, someone decides to drop everything in the
database directly without initiating it again.
*/
Needs to be in this try because it throws the database doesn't have the schema_version
table, which may happen if in an arbitrary test, someone decides to drop everything in the
database directly without initiating it again.
*/
flyway.clean()
} catch {
case NonFatal(e) => LTSVLogger.error(e)
Expand Down

0 comments on commit 816d8bf

Please sign in to comment.