AutoRollback

scalikejdbc.specs2.AutoRollback

Automatic Rollback support for specs2.

If you want to test this Member object,

import scalikejdbc._

object Member {
 def create(id: Long, name: String)(implicit session: DBSession = AutoSession) {
   SQL("insert into members values (?, ?)".bind(id, name).update.apply()
 }
}

Use scalikejdbc.specs2.AutoRollback like this:

import org.specs2.Specification
import scalikejdbc.specs2.AutoRollback

class MemberSpec extends Specification { def is =

 "Member should create a new record" ! autoRollback().create ^
 "LegacyAccount should create a new record" ! db2AutoRollback().create ^ end

 case class autoRollback() extends AutoRollback {
   def create = this {
     Member.create(1, "Alice")
     Member.find(1).isDefined must beTrue
   }
 }

 case class db2AutoRollback() extends AutoRollback {
   override def db() = NamedDB("db2").toDB
   def create = this {
     LegacyAccount.create(2, "Bob")
     LegacyAccount.find(2).isDefined must beTrue
   }
 }
}

Attributes

Source
AutoRollback.scala
Graph
Supertypes
trait LoanPattern
trait After
trait Context
trait Scope
trait Scope
class Object
trait Matchable
class Any
Show all

Members list

Type members

Inherited types

type Closable = { def close(): Unit; }

Attributes

Inherited from:
LoanPattern
Source
LoanPattern.scala

Value members

Inherited methods

override def after: Any

override this method to provide the after behavior

override this method to provide the after behavior

Attributes

Definition Classes
AutoRollbackLike -> After
Inherited from:
AutoRollbackLike
Source
AutoRollbackLike.scala
def andThen(a: After): After

sequence the actions of 2 After traits

sequence the actions of 2 After traits

Attributes

Inherited from:
After
Source
Context.scala
def apply[T : AsResult](a: => T): Result

execute an action returning a Result and finally the after action

execute an action returning a Result and finally the after action

Attributes

Inherited from:
After
Source
Context.scala
def compose(a: After): After

compose the actions of 2 After traits

compose the actions of 2 After traits

Attributes

Inherited from:
After
Source
Context.scala
def db(): DB

Creates a scalikejdbc.DB instance.

Creates a scalikejdbc.DB instance.

Attributes

Returns

DB instance

Inherited from:
AutoRollbackLike
Source
AutoRollbackLike.scala
def fixture(implicit session: DBSession): Unit

Prepares database for the test.

Prepares database for the test.

Value parameters

session

db session implicitly

Attributes

Inherited from:
AutoRollbackLike
Source
AutoRollbackLike.scala
def futureUsing[R <: Closable, A](resource: R)(f: R => Future[A])(implicit ec: ExecutionContext): Future[A]

Guarantees a Closeable resource will be closed after being passed to a block that takes the resource as a parameter and returns a Future.

Guarantees a Closeable resource will be closed after being passed to a block that takes the resource as a parameter and returns a Future.

Attributes

Inherited from:
LoanPattern
Source
LoanPattern.scala
def using[R <: Closable, A](resource: R)(f: R => A): A

Attributes

Inherited from:
LoanPattern
Source
LoanPattern.scala

Inherited fields

val _db: DB

Attributes

Inherited from:
AutoRollbackLike
Source
AutoRollbackLike.scala

Implicits

Inherited implicits

implicit val session: DBSession

Attributes

Inherited from:
AutoRollbackLike
Source
AutoRollbackLike.scala