mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 15:35:59 +01:00
Fix compilation error service test case
This commit is contained in:
@@ -9,13 +9,13 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
|
||||
"AccountService" should {
|
||||
val RootMailAddress = "root@localhost"
|
||||
|
||||
"getAllUsers" in { withTestDB{
|
||||
"getAllUsers" in { withTestDB { implicit session =>
|
||||
AccountService.getAllUsers() must be like{
|
||||
case List(model.Account("root", "root", RootMailAddress, _, true, _, _, _, None, None, false, false)) => ok
|
||||
}
|
||||
}}
|
||||
|
||||
"getAccountByUserName" in { withTestDB{
|
||||
"getAccountByUserName" in { withTestDB { implicit session =>
|
||||
AccountService.getAccountByUserName("root") must beSome.like{
|
||||
case user => user.userName must_== "root"
|
||||
}
|
||||
@@ -23,11 +23,11 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
|
||||
AccountService.getAccountByUserName("invalid user name") must beNone
|
||||
}}
|
||||
|
||||
"getAccountByMailAddress" in { withTestDB{
|
||||
"getAccountByMailAddress" in { withTestDB { implicit session =>
|
||||
AccountService.getAccountByMailAddress(RootMailAddress) must beSome
|
||||
}}
|
||||
|
||||
"updateLastLoginDate" in { withTestDB{
|
||||
"updateLastLoginDate" in { withTestDB { implicit session =>
|
||||
val root = "root"
|
||||
def user() =
|
||||
AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists"))
|
||||
@@ -46,7 +46,7 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
|
||||
}
|
||||
}}
|
||||
|
||||
"updateAccount" in { withTestDB{
|
||||
"updateAccount" in { withTestDB { implicit session =>
|
||||
val root = "root"
|
||||
def user() =
|
||||
AccountService.getAccountByUserName(root).getOrElse(sys.error(s"user $root does not exists"))
|
||||
@@ -56,7 +56,7 @@ class AccountServiceSpec extends Specification with ServiceSpecBase {
|
||||
user().mailAddress must_== newAddress
|
||||
}}
|
||||
|
||||
"group" in { withTestDB {
|
||||
"group" in { withTestDB { implicit session =>
|
||||
val group1 = "group1"
|
||||
val user1 = "root"
|
||||
AccountService.createGroup(group1, None)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package service
|
||||
|
||||
import scala.slick.session.Database
|
||||
import model.simple._
|
||||
import util.ControlUtil._
|
||||
import java.sql.DriverManager
|
||||
import org.apache.commons.io.FileUtils
|
||||
@@ -9,15 +9,15 @@ import java.io.File
|
||||
|
||||
trait ServiceSpecBase {
|
||||
|
||||
def withTestDB[A](action: => A): A = {
|
||||
def withTestDB[A](action: (Session) => 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
|
||||
Database.forURL(url, user, pass).withSession { session =>
|
||||
action(session)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user