mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 23:45:50 +01:00
add CommitStatus table and model and service.
This commit is contained in:
25
src/test/scala/model/CommitStateSpec.scala
Normal file
25
src/test/scala/model/CommitStateSpec.scala
Normal file
@@ -0,0 +1,25 @@
|
||||
package model
|
||||
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
import CommitState._
|
||||
|
||||
class CommitStateSpec extends Specification {
|
||||
"CommitState" should {
|
||||
"combine empty must eq PENDING" in {
|
||||
combine(Set()) must_== PENDING
|
||||
}
|
||||
"combine includes ERROR must eq FAILURE" in {
|
||||
combine(Set(ERROR, SUCCESS, PENDING)) must_== FAILURE
|
||||
}
|
||||
"combine includes FAILURE must eq peinding" in {
|
||||
combine(Set(FAILURE, SUCCESS, PENDING)) must_== FAILURE
|
||||
}
|
||||
"combine includes PENDING must eq peinding" in {
|
||||
combine(Set(PENDING, SUCCESS)) must_== PENDING
|
||||
}
|
||||
"combine only SUCCESS must eq SUCCESS" in {
|
||||
combine(Set(SUCCESS)) must_== SUCCESS
|
||||
}
|
||||
}
|
||||
}
|
||||
77
src/test/scala/service/CommitStateServiceSpec.scala
Normal file
77
src/test/scala/service/CommitStateServiceSpec.scala
Normal file
@@ -0,0 +1,77 @@
|
||||
package service
|
||||
import org.specs2.mutable.Specification
|
||||
import java.util.Date
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
class CommitStatusServiceSpec extends Specification with ServiceSpecBase with CommitStatusService
|
||||
with RepositoryService with AccountService{
|
||||
def generateNewAccount(name:String)(implicit s:Session):Account = {
|
||||
createAccount(name, name, name, s"${name}@example.com", false, None)
|
||||
getAccountByUserName(name).get
|
||||
}
|
||||
val now = new java.util.Date()
|
||||
val fixture1 = CommitStatus(
|
||||
userName = "root",
|
||||
repositoryName = "repo",
|
||||
commitId = "0e97b8f59f7cdd709418bb59de53f741fd1c1bd7",
|
||||
context = "jenkins/test",
|
||||
creator = "tester",
|
||||
state = CommitState.PENDING,
|
||||
targetUrl = Some("http://example.com/target"),
|
||||
description = Some("description"),
|
||||
updatedDate = now,
|
||||
registeredDate = now)
|
||||
def findById(id: Int)(implicit s:Session) = CommitStatuses.filter(_.byPrimaryKey(id)).firstOption
|
||||
def generateFixture1(tester:Account)(implicit s:Session) = createCommitStatus(
|
||||
userName = fixture1.userName,
|
||||
repositoryName = fixture1.repositoryName,
|
||||
sha = fixture1.commitId,
|
||||
context = fixture1.context,
|
||||
state = fixture1.state,
|
||||
targetUrl = fixture1.targetUrl,
|
||||
description = fixture1.description,
|
||||
creator = tester,
|
||||
now = fixture1.registeredDate)
|
||||
"CommitStatusService" should {
|
||||
"createCommitState can insert and update" in { withTestDB { implicit session =>
|
||||
val tester = generateNewAccount(fixture1.creator)
|
||||
createRepository(fixture1.repositoryName,fixture1.userName,None,false)
|
||||
val id = generateFixture1(tester:Account)
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, id) must_==
|
||||
Some(fixture1.copy(commitStatusId=id))
|
||||
// other one can update
|
||||
val tester2 = generateNewAccount("tester2")
|
||||
val time2 = new java.util.Date();
|
||||
val id2 = createCommitStatus(
|
||||
userName = fixture1.userName,
|
||||
repositoryName = fixture1.repositoryName,
|
||||
sha = fixture1.commitId,
|
||||
context = fixture1.context,
|
||||
state = CommitState.SUCCESS,
|
||||
targetUrl = Some("http://example.com/target2"),
|
||||
description = Some("description2"),
|
||||
creator = tester2,
|
||||
now = time2)
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, id2) must_== Some(fixture1.copy(
|
||||
commitStatusId = id,
|
||||
creator = "tester2",
|
||||
state = CommitState.SUCCESS,
|
||||
targetUrl = Some("http://example.com/target2"),
|
||||
description = Some("description2"),
|
||||
updatedDate = time2))
|
||||
}}
|
||||
"getCommitStatus can find by commitId and context" in { withTestDB { implicit session =>
|
||||
val tester = generateNewAccount(fixture1.creator)
|
||||
createRepository(fixture1.repositoryName,fixture1.userName,None,false)
|
||||
val id = generateFixture1(tester:Account)
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, fixture1.commitId, fixture1.context) must_== Some(fixture1.copy(commitStatusId=id))
|
||||
}}
|
||||
"getCommitStatus can find by commitStatusId" in { withTestDB { implicit session =>
|
||||
val tester = generateNewAccount(fixture1.creator)
|
||||
createRepository(fixture1.repositoryName,fixture1.userName,None,false)
|
||||
val id = generateFixture1(tester:Account)
|
||||
getCommitStatus(fixture1.userName, fixture1.repositoryName, id) must_== Some(fixture1.copy(commitStatusId=id))
|
||||
}}
|
||||
}
|
||||
}
|
||||
37
src/test/scala/service/RepositoryServiceSpec.scala
Normal file
37
src/test/scala/service/RepositoryServiceSpec.scala
Normal file
@@ -0,0 +1,37 @@
|
||||
package service
|
||||
import org.specs2.mutable.Specification
|
||||
import java.util.Date
|
||||
import model._
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
class RepositoryServiceSpec extends Specification with ServiceSpecBase with RepositoryService with AccountService{
|
||||
def generateNewAccount(name:String)(implicit s:Session):Account = {
|
||||
createAccount(name, name, name, s"${name}@example.com", false, None)
|
||||
getAccountByUserName(name).get
|
||||
}
|
||||
"RepositoryService" should {
|
||||
"renameRepository can rename CommitState" in { withTestDB { implicit session =>
|
||||
val tester = generateNewAccount("tester")
|
||||
createRepository("repo","root",None,false)
|
||||
val commitStatusService = new CommitStatusService{}
|
||||
val id = commitStatusService.createCommitStatus(
|
||||
userName = "root",
|
||||
repositoryName = "repo",
|
||||
sha = "0e97b8f59f7cdd709418bb59de53f741fd1c1bd7",
|
||||
context = "jenkins/test",
|
||||
state = CommitState.PENDING,
|
||||
targetUrl = Some("http://example.com/target"),
|
||||
description = Some("description"),
|
||||
creator = tester,
|
||||
now = new java.util.Date)
|
||||
val org = commitStatusService.getCommitStatus("root","repo", id).get
|
||||
renameRepository("root","repo","tester","repo2")
|
||||
val neo = commitStatusService.getCommitStatus("tester","repo2", org.commitId, org.context).get
|
||||
neo must_==
|
||||
org.copy(
|
||||
commitStatusId=neo.commitStatusId,
|
||||
repositoryName="repo2",
|
||||
userName="tester")
|
||||
}}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user