Small fix for #147

This commit is contained in:
takezoe
2013-10-22 01:09:22 +09:00
parent 90ab882e8e
commit f3ad1a019d
2 changed files with 3 additions and 3 deletions

View File

@@ -3,14 +3,14 @@ package service
import org.specs2.mutable.Specification
import java.util.Date
class AccountServiceSpec extends Specification with SpecBase {
class AccountServiceServiceSpec extends Specification with ServiceSpecBase {
"AccountService" should {
val RootMailAddress = "root@localhost"
"getAllUsers" in { withTestDB{
AccountService.getAllUsers must be like{
case List(model.Account("root", RootMailAddress, _, true, _, _, _, None, None, false)) => ok
case List(model.Account("root", "root", RootMailAddress, _, true, _, _, _, None, None, false)) => ok
}
}}

View File

@@ -0,0 +1,26 @@
package service
import scala.slick.session.Database
import util.ControlUtil._
import java.sql.DriverManager
import org.apache.commons.io.FileUtils
import scala.util.Random
import java.io.File
trait ServiceSpecBase {
def withTestDB[A](action: => A): A = {
util.FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)){
dir =>
val (url, user, pass) = (s"jdbc:h2:${dir}", "sa", "sa")
org.h2.Driver.load()
using(DriverManager.getConnection(url, user, pass)){ conn =>
servlet.AutoUpdate.versions.reverse.foreach(_.update(conn))
}
Database.forURL(url, user, pass).withSession {
action
}
}
}
}