diff --git a/src/test/scala/gitbucket/core/service/AccountServiceSpec.scala b/src/test/scala/gitbucket/core/service/AccountServiceSpec.scala
index 1c4793f..2e83d41 100644
--- a/src/test/scala/gitbucket/core/service/AccountServiceSpec.scala
+++ b/src/test/scala/gitbucket/core/service/AccountServiceSpec.scala
@@ -1,6 +1,6 @@
package gitbucket.core.service
-import gitbucket.core.model.GroupMember
+import gitbucket.core.model.{Account, GroupMember}
import org.specs2.mutable.Specification
import java.util.Date
@@ -11,7 +11,7 @@
"getAllUsers" in { withTestDB { implicit session =>
AccountService.getAllUsers() must be like{
- case List(model.Account("root", "root", RootMailAddress, _, true, _, _, _, None, None, false, false)) => ok
+ case List(Account("root", "root", RootMailAddress, _, true, _, _, _, None, None, false, false)) => ok
}
}}
diff --git a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala
index 850a6fa..166ba2d 100644
--- a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala
+++ b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala
@@ -1,8 +1,8 @@
package gitbucket.core.service
-import gitbucket.core.model.Profile
import gitbucket.core.servlet.AutoUpdate
import gitbucket.core.util.{ControlUtil, DatabaseConfig, FileUtil}
+import gitbucket.core.model.Profile._
import profile.simple._
import ControlUtil._
import java.sql.DriverManager
diff --git a/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala b/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala
new file mode 100644
index 0000000..10c9cf9
--- /dev/null
+++ b/src/test/scala/gitbucket/core/view/AvatarImageProviderSpec.scala
@@ -0,0 +1,121 @@
+package gitbucket.core.view
+
+import java.util.Date
+
+import gitbucket.core.model.Account
+import gitbucket.core.service.{SystemSettingsService, RequestCache}
+import gitbucket.core.controller.Context
+import org.specs2.mutable._
+import org.specs2.mock.Mockito
+import SystemSettingsService.SystemSettings
+import javax.servlet.http.HttpServletRequest
+import play.twirl.api.Html
+
+class AvatarImageProviderSpec extends Specification with Mockito {
+
+ val request = mock[HttpServletRequest]
+ request.getRequestURL returns new StringBuffer("http://localhost:8080/path.html")
+ request.getRequestURI returns "/path.html"
+ request.getContextPath returns ""
+
+ "getAvatarImageHtml" should {
+ "show Gravatar image for no image account if gravatar integration is enabled" in {
+ implicit val context = Context(createSystemSettings(true), None, request)
+ val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
+
+ provider.toHtml("user", 32).toString mustEqual
+ "
"
+ }
+
+ "show uploaded image even if gravatar integration is enabled" in {
+ implicit val context = Context(createSystemSettings(true), None, request)
+ val provider = new AvatarImageProviderImpl(Some(createAccount(Some("icon.png"))))
+
+ provider.toHtml("user", 32).toString mustEqual
+ "
"
+ }
+
+ "show local image for no image account if gravatar integration is disabled" in {
+ implicit val context = Context(createSystemSettings(false), None, request)
+ val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
+
+ provider.toHtml("user", 32).toString mustEqual
+ "
"
+ }
+
+ "show Gravatar image for specified mail address if gravatar integration is enabled" in {
+ implicit val context = Context(createSystemSettings(true), None, request)
+ val provider = new AvatarImageProviderImpl(None)
+
+ provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
+ "
"
+ }
+
+ "show unknown image for unknown user if gravatar integration is enabled" in {
+ implicit val context = Context(createSystemSettings(true), None, request)
+ val provider = new AvatarImageProviderImpl(None)
+
+ provider.toHtml("user", 20).toString mustEqual
+ "
"
+ }
+
+ "show unknown image for specified mail address if gravatar integration is disabled" in {
+ implicit val context = Context(createSystemSettings(false), None, request)
+ val provider = new AvatarImageProviderImpl(None)
+
+ provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
+ "
"
+ }
+
+ "add tooltip if it's enabled" in {
+ implicit val context = Context(createSystemSettings(false), None, request)
+ val provider = new AvatarImageProviderImpl(None)
+
+ provider.toHtml("user", 20, "hoge@hoge.com", true).toString mustEqual
+ "
"
+ }
+ }
+
+ private def createAccount(image: Option[String]) =
+ Account(
+ userName = "user",
+ fullName = "user@localhost",
+ mailAddress = "",
+ password = "",
+ isAdmin = false,
+ url = None,
+ registeredDate = new Date(),
+ updatedDate = new Date(),
+ lastLoginDate = None,
+ image = image,
+ isGroupAccount = false,
+ isRemoved = false)
+
+ private def createSystemSettings(useGravatar: Boolean) =
+ SystemSettings(
+ baseUrl = None,
+ information = None,
+ allowAccountRegistration = false,
+ allowAnonymousAccess = true,
+ isCreateRepoOptionPublic = true,
+ gravatar = useGravatar,
+ notification = false,
+ ssh = false,
+ sshPort = None,
+ smtp = None,
+ ldapAuthentication = false,
+ ldap = None)
+
+ /**
+ * Adapter to test AvatarImageProviderImpl.
+ */
+ class AvatarImageProviderImpl(account: Option[Account]) extends AvatarImageProvider with RequestCache {
+
+ def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)
+ (implicit context: Context): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip)
+
+ override def getAccountByMailAddress(mailAddress: String)(implicit context: Context): Option[Account] = account
+ override def getAccountByUserName(userName: String)(implicit context: Context): Option[Account] = account
+ }
+
+}
diff --git a/src/test/scala/gitbucket/core/view/GitBucketHtmlSerializerSpec.scala b/src/test/scala/gitbucket/core/view/GitBucketHtmlSerializerSpec.scala
new file mode 100644
index 0000000..82fb3d9
--- /dev/null
+++ b/src/test/scala/gitbucket/core/view/GitBucketHtmlSerializerSpec.scala
@@ -0,0 +1,93 @@
+package gitbucket.core.view
+
+import org.specs2.mutable._
+
+class GitBucketHtmlSerializerSpec extends Specification {
+
+ import GitBucketHtmlSerializer._
+
+ "generateAnchorName" should {
+ "convert whitespace characters to hyphens" in {
+ val before = "foo bar baz"
+ val after = generateAnchorName(before)
+ after mustEqual "foo-bar-baz"
+ }
+
+ "normalize characters with diacritics" in {
+ val before = "Dónde estará mi vida"
+ val after = generateAnchorName(before)
+ after mustEqual "do%cc%81nde-estara%cc%81-mi-vida"
+ }
+
+ "omit special characters" in {
+ val before = "foo!bar@baz>9000"
+ val after = generateAnchorName(before)
+ after mustEqual "foo%21bar%40baz%3e9000"
+ }
+ }
+
+ "escapeTaskList" should {
+ "convert '- [ ] ' to '* task: :'" in {
+ val before = "- [ ] aaaa"
+ val after = escapeTaskList(before)
+ after mustEqual "* task: : aaaa"
+ }
+
+ "convert ' - [ ] ' to ' * task: :'" in {
+ val before = " - [ ] aaaa"
+ val after = escapeTaskList(before)
+ after mustEqual " * task: : aaaa"
+ }
+
+ "convert only first '- [ ] '" in {
+ val before = " - [ ] aaaa - [ ] bbb"
+ val after = escapeTaskList(before)
+ after mustEqual " * task: : aaaa - [ ] bbb"
+ }
+
+ "convert '- [x] ' to '* task:x:'" in {
+ val before = " - [x] aaaa"
+ val after = escapeTaskList(before)
+ after mustEqual " * task:x: aaaa"
+ }
+
+ "convert multi lines" in {
+ val before = """
+tasks
+- [x] aaaa
+- [ ] bbb
+"""
+ val after = escapeTaskList(before)
+ after mustEqual """
+tasks
+* task:x: aaaa
+* task: : bbb
+"""
+ }
+
+ "no convert if inserted before '- [ ] '" in {
+ val before = " a - [ ] aaaa"
+ val after = escapeTaskList(before)
+ after mustEqual " a - [ ] aaaa"
+ }
+
+ "no convert '- [] '" in {
+ val before = " - [] aaaa"
+ val after = escapeTaskList(before)
+ after mustEqual " - [] aaaa"
+ }
+
+ "no convert '- [ ]a'" in {
+ val before = " - [ ]a aaaa"
+ val after = escapeTaskList(before)
+ after mustEqual " - [ ]a aaaa"
+ }
+
+ "no convert '-[ ] '" in {
+ val before = " -[ ] aaaa"
+ val after = escapeTaskList(before)
+ after mustEqual " -[ ] aaaa"
+ }
+ }
+}
+
diff --git a/src/test/scala/gitbucket/core/view/PaginationSpec.scala b/src/test/scala/gitbucket/core/view/PaginationSpec.scala
new file mode 100644
index 0000000..785c761
--- /dev/null
+++ b/src/test/scala/gitbucket/core/view/PaginationSpec.scala
@@ -0,0 +1,70 @@
+package gitbucket.core.view
+
+import gitbucket.core.util.ControlUtil
+import org.specs2.mutable._
+import ControlUtil._
+
+class PaginationSpec extends Specification {
+
+ "max" should {
+ "return max page number" in {
+ val pagination = Pagination(1, 100, 10, 6)
+ pagination.max mustEqual 10
+ }
+ }
+
+ "omitLeft and omitRight" should {
+ "return true if pagination links at their side will be omitted" in {
+ defining(Pagination(1, 100, 10, 6)){ pagination =>
+ pagination.omitLeft mustEqual false
+ pagination.omitRight mustEqual true
+ }
+ defining(Pagination(9, 100, 10, 6)){ pagination =>
+ pagination.omitLeft mustEqual true
+ pagination.omitRight mustEqual false
+ }
+ }
+ }
+
+ "visibleFor" should {
+ "return true for visible pagination links" in {
+ defining(Pagination(1, 100, 10, 6)){ pagination =>
+ pagination.visibleFor(1) mustEqual true
+ pagination.visibleFor(2) mustEqual true
+ pagination.visibleFor(3) mustEqual true
+ pagination.visibleFor(4) mustEqual true
+ pagination.visibleFor(5) mustEqual true
+ pagination.visibleFor(6) mustEqual false
+ pagination.visibleFor(7) mustEqual false
+ pagination.visibleFor(8) mustEqual false
+ pagination.visibleFor(9) mustEqual false
+ pagination.visibleFor(10) mustEqual true
+ }
+ defining(Pagination(5, 100, 10, 6)){ pagination =>
+ pagination.visibleFor(1) mustEqual true
+ pagination.visibleFor(2) mustEqual false
+ pagination.visibleFor(3) mustEqual false
+ pagination.visibleFor(4) mustEqual true
+ pagination.visibleFor(5) mustEqual true
+ pagination.visibleFor(6) mustEqual true
+ pagination.visibleFor(7) mustEqual false
+ pagination.visibleFor(8) mustEqual false
+ pagination.visibleFor(9) mustEqual false
+ pagination.visibleFor(10) mustEqual true
+ }
+ defining(Pagination(8, 100, 10, 6)){ pagination =>
+ pagination.visibleFor(1) mustEqual true
+ pagination.visibleFor(2) mustEqual false
+ pagination.visibleFor(3) mustEqual false
+ pagination.visibleFor(4) mustEqual false
+ pagination.visibleFor(5) mustEqual false
+ pagination.visibleFor(6) mustEqual true
+ pagination.visibleFor(7) mustEqual true
+ pagination.visibleFor(8) mustEqual true
+ pagination.visibleFor(9) mustEqual true
+ pagination.visibleFor(10) mustEqual true
+ }
+ }
+ }
+
+}
diff --git a/src/test/scala/view/AvatarImageProviderSpec.scala b/src/test/scala/view/AvatarImageProviderSpec.scala
deleted file mode 100644
index ca7bda4..0000000
--- a/src/test/scala/view/AvatarImageProviderSpec.scala
+++ /dev/null
@@ -1,121 +0,0 @@
-package view
-
-import java.util.Date
-
-import gitbucket.core.model.Account
-import gitbucket.core.service.{SystemSettingsService, RequestCache}
-import gitbucket.core.view.AvatarImageProvider
-import org.specs2.mutable._
-import org.specs2.mock.Mockito
-import SystemSettingsService.SystemSettings
-import play.twirl.api.Html
-import javax.servlet.http.HttpServletRequest
-
-class AvatarImageProviderSpec extends Specification with Mockito {
-
- val request = mock[HttpServletRequest]
- request.getRequestURL returns new StringBuffer("http://localhost:8080/path.html")
- request.getRequestURI returns "/path.html"
- request.getContextPath returns ""
-
- "getAvatarImageHtml" should {
- "show Gravatar image for no image account if gravatar integration is enabled" in {
- implicit val context = app.Context(createSystemSettings(true), None, request)
- val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
-
- provider.toHtml("user", 32).toString mustEqual
- "
"
- }
-
- "show uploaded image even if gravatar integration is enabled" in {
- implicit val context = app.Context(createSystemSettings(true), None, request)
- val provider = new AvatarImageProviderImpl(Some(createAccount(Some("icon.png"))))
-
- provider.toHtml("user", 32).toString mustEqual
- "
"
- }
-
- "show local image for no image account if gravatar integration is disabled" in {
- implicit val context = app.Context(createSystemSettings(false), None, request)
- val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
-
- provider.toHtml("user", 32).toString mustEqual
- "
"
- }
-
- "show Gravatar image for specified mail address if gravatar integration is enabled" in {
- implicit val context = app.Context(createSystemSettings(true), None, request)
- val provider = new AvatarImageProviderImpl(None)
-
- provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
- "
"
- }
-
- "show unknown image for unknown user if gravatar integration is enabled" in {
- implicit val context = app.Context(createSystemSettings(true), None, request)
- val provider = new AvatarImageProviderImpl(None)
-
- provider.toHtml("user", 20).toString mustEqual
- "
"
- }
-
- "show unknown image for specified mail address if gravatar integration is disabled" in {
- implicit val context = app.Context(createSystemSettings(false), None, request)
- val provider = new AvatarImageProviderImpl(None)
-
- provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
- "
"
- }
-
- "add tooltip if it's enabled" in {
- implicit val context = app.Context(createSystemSettings(false), None, request)
- val provider = new AvatarImageProviderImpl(None)
-
- provider.toHtml("user", 20, "hoge@hoge.com", true).toString mustEqual
- "
"
- }
- }
-
- private def createAccount(image: Option[String]) =
- Account(
- userName = "user",
- fullName = "user@localhost",
- mailAddress = "",
- password = "",
- isAdmin = false,
- url = None,
- registeredDate = new Date(),
- updatedDate = new Date(),
- lastLoginDate = None,
- image = image,
- isGroupAccount = false,
- isRemoved = false)
-
- private def createSystemSettings(useGravatar: Boolean) =
- SystemSettings(
- baseUrl = None,
- information = None,
- allowAccountRegistration = false,
- allowAnonymousAccess = true,
- isCreateRepoOptionPublic = true,
- gravatar = useGravatar,
- notification = false,
- ssh = false,
- sshPort = None,
- smtp = None,
- ldapAuthentication = false,
- ldap = None)
-
- /**
- * Adapter to test AvatarImageProviderImpl.
- */
- class AvatarImageProviderImpl(account: Option[Account]) extends AvatarImageProvider with RequestCache {
-
- def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)
- (implicit context: app.Context): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip)
-
- override def getAccountByMailAddress(mailAddress: String)(implicit context: app.Context): Option[Account] = account
- override def getAccountByUserName(userName: String)(implicit context: app.Context): Option[Account] = account
- }
-
-}
diff --git a/src/test/scala/view/GitBucketHtmlSerializerSpec.scala b/src/test/scala/view/GitBucketHtmlSerializerSpec.scala
deleted file mode 100644
index 71a0615..0000000
--- a/src/test/scala/view/GitBucketHtmlSerializerSpec.scala
+++ /dev/null
@@ -1,94 +0,0 @@
-package view
-
-import gitbucket.core.view.GitBucketHtmlSerializer
-import org.specs2.mutable._
-
-class GitBucketHtmlSerializerSpec extends Specification {
-
- import GitBucketHtmlSerializer._
-
- "generateAnchorName" should {
- "convert whitespace characters to hyphens" in {
- val before = "foo bar baz"
- val after = generateAnchorName(before)
- after mustEqual "foo-bar-baz"
- }
-
- "normalize characters with diacritics" in {
- val before = "Dónde estará mi vida"
- val after = generateAnchorName(before)
- after mustEqual "do%cc%81nde-estara%cc%81-mi-vida"
- }
-
- "omit special characters" in {
- val before = "foo!bar@baz>9000"
- val after = generateAnchorName(before)
- after mustEqual "foo%21bar%40baz%3e9000"
- }
- }
-
- "escapeTaskList" should {
- "convert '- [ ] ' to '* task: :'" in {
- val before = "- [ ] aaaa"
- val after = escapeTaskList(before)
- after mustEqual "* task: : aaaa"
- }
-
- "convert ' - [ ] ' to ' * task: :'" in {
- val before = " - [ ] aaaa"
- val after = escapeTaskList(before)
- after mustEqual " * task: : aaaa"
- }
-
- "convert only first '- [ ] '" in {
- val before = " - [ ] aaaa - [ ] bbb"
- val after = escapeTaskList(before)
- after mustEqual " * task: : aaaa - [ ] bbb"
- }
-
- "convert '- [x] ' to '* task:x:'" in {
- val before = " - [x] aaaa"
- val after = escapeTaskList(before)
- after mustEqual " * task:x: aaaa"
- }
-
- "convert multi lines" in {
- val before = """
-tasks
-- [x] aaaa
-- [ ] bbb
-"""
- val after = escapeTaskList(before)
- after mustEqual """
-tasks
-* task:x: aaaa
-* task: : bbb
-"""
- }
-
- "no convert if inserted before '- [ ] '" in {
- val before = " a - [ ] aaaa"
- val after = escapeTaskList(before)
- after mustEqual " a - [ ] aaaa"
- }
-
- "no convert '- [] '" in {
- val before = " - [] aaaa"
- val after = escapeTaskList(before)
- after mustEqual " - [] aaaa"
- }
-
- "no convert '- [ ]a'" in {
- val before = " - [ ]a aaaa"
- val after = escapeTaskList(before)
- after mustEqual " - [ ]a aaaa"
- }
-
- "no convert '-[ ] '" in {
- val before = " -[ ] aaaa"
- val after = escapeTaskList(before)
- after mustEqual " -[ ] aaaa"
- }
- }
-}
-
diff --git a/src/test/scala/view/PaginationSpec.scala b/src/test/scala/view/PaginationSpec.scala
deleted file mode 100644
index f320e38..0000000
--- a/src/test/scala/view/PaginationSpec.scala
+++ /dev/null
@@ -1,71 +0,0 @@
-package view
-
-import gitbucket.core.util.ControlUtil
-import gitbucket.core.view.Pagination
-import org.specs2.mutable._
-import ControlUtil._
-
-class PaginationSpec extends Specification {
-
- "max" should {
- "return max page number" in {
- val pagination = Pagination(1, 100, 10, 6)
- pagination.max mustEqual 10
- }
- }
-
- "omitLeft and omitRight" should {
- "return true if pagination links at their side will be omitted" in {
- defining(Pagination(1, 100, 10, 6)){ pagination =>
- pagination.omitLeft mustEqual false
- pagination.omitRight mustEqual true
- }
- defining(Pagination(9, 100, 10, 6)){ pagination =>
- pagination.omitLeft mustEqual true
- pagination.omitRight mustEqual false
- }
- }
- }
-
- "visibleFor" should {
- "return true for visible pagination links" in {
- defining(Pagination(1, 100, 10, 6)){ pagination =>
- pagination.visibleFor(1) mustEqual true
- pagination.visibleFor(2) mustEqual true
- pagination.visibleFor(3) mustEqual true
- pagination.visibleFor(4) mustEqual true
- pagination.visibleFor(5) mustEqual true
- pagination.visibleFor(6) mustEqual false
- pagination.visibleFor(7) mustEqual false
- pagination.visibleFor(8) mustEqual false
- pagination.visibleFor(9) mustEqual false
- pagination.visibleFor(10) mustEqual true
- }
- defining(Pagination(5, 100, 10, 6)){ pagination =>
- pagination.visibleFor(1) mustEqual true
- pagination.visibleFor(2) mustEqual false
- pagination.visibleFor(3) mustEqual false
- pagination.visibleFor(4) mustEqual true
- pagination.visibleFor(5) mustEqual true
- pagination.visibleFor(6) mustEqual true
- pagination.visibleFor(7) mustEqual false
- pagination.visibleFor(8) mustEqual false
- pagination.visibleFor(9) mustEqual false
- pagination.visibleFor(10) mustEqual true
- }
- defining(Pagination(8, 100, 10, 6)){ pagination =>
- pagination.visibleFor(1) mustEqual true
- pagination.visibleFor(2) mustEqual false
- pagination.visibleFor(3) mustEqual false
- pagination.visibleFor(4) mustEqual false
- pagination.visibleFor(5) mustEqual false
- pagination.visibleFor(6) mustEqual true
- pagination.visibleFor(7) mustEqual true
- pagination.visibleFor(8) mustEqual true
- pagination.visibleFor(9) mustEqual true
- pagination.visibleFor(10) mustEqual true
- }
- }
- }
-
-}