mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Use Context#settings instead of loadSystemSettings()
This commit is contained in:
@@ -10,53 +10,58 @@ import twirl.api.Html
|
||||
|
||||
class AvatarImageProviderSpec extends Specification {
|
||||
|
||||
implicit val context = app.Context("", None, null)
|
||||
|
||||
"getAvatarImageHtml" should {
|
||||
"show Gravatar image for no image account if gravatar integration is enabled" in {
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(None)), createSystemSettings(true))
|
||||
implicit val context = app.Context(createSystemSettings(true), None, null)
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
|
||||
|
||||
provider.toHtml("user", 20).toString mustEqual
|
||||
"<img src=\"https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=20\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
|
||||
}
|
||||
|
||||
"show uploaded image even if gravatar integration is enabled" in {
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(Some("icon.png"))), createSystemSettings(true))
|
||||
implicit val context = app.Context(createSystemSettings(true), None, null)
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(Some("icon.png"))))
|
||||
|
||||
provider.toHtml("user", 20).toString mustEqual
|
||||
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
|
||||
}
|
||||
|
||||
"show local image for no image account if gravatar integration is disabled" in {
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(None)), createSystemSettings(false))
|
||||
implicit val context = app.Context(createSystemSettings(false), None, null)
|
||||
val provider = new AvatarImageProviderImpl(Some(createAccount(None)))
|
||||
|
||||
provider.toHtml("user", 20).toString mustEqual
|
||||
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
|
||||
}
|
||||
|
||||
"show Gravatar image for specified mail address if gravatar integration is enabled" in {
|
||||
val provider = new AvatarImageProviderImpl(None, createSystemSettings(true))
|
||||
implicit val context = app.Context(createSystemSettings(true), None, null)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
|
||||
"<img src=\"https://www.gravatar.com/avatar/4712f9b0e63f56ad952ad387eaa23b9c?s=20\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
|
||||
}
|
||||
|
||||
"show unknown image for unknown user if gravatar integration is enabled" in {
|
||||
val provider = new AvatarImageProviderImpl(None, createSystemSettings(true))
|
||||
implicit val context = app.Context(createSystemSettings(true), None, null)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20).toString mustEqual
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
|
||||
}
|
||||
|
||||
"show unknown image for specified mail address if gravatar integration is disabled" in {
|
||||
val provider = new AvatarImageProviderImpl(None, createSystemSettings(false))
|
||||
implicit val context = app.Context(createSystemSettings(false), None, null)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
|
||||
}
|
||||
|
||||
"add tooltip if it's enabled" in {
|
||||
val provider = new AvatarImageProviderImpl(None, createSystemSettings(false))
|
||||
implicit val context = app.Context(createSystemSettings(false), None, null)
|
||||
val provider = new AvatarImageProviderImpl(None)
|
||||
|
||||
provider.toHtml("user", 20, "hoge@hoge.com", true).toString mustEqual
|
||||
"<img src=\"/_unknown/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" data-toggle=\"tooltip\" title=\"user\"/>"
|
||||
@@ -80,7 +85,7 @@ class AvatarImageProviderSpec extends Specification {
|
||||
|
||||
private def createSystemSettings(useGravatar: Boolean) =
|
||||
SystemSettings(
|
||||
baseUrl = None,
|
||||
baseUrl = Some(""),
|
||||
allowAccountRegistration = false,
|
||||
gravatar = useGravatar,
|
||||
notification = false,
|
||||
@@ -93,15 +98,13 @@ class AvatarImageProviderSpec extends Specification {
|
||||
/**
|
||||
* Adapter to test AvatarImageProviderImpl.
|
||||
*/
|
||||
class AvatarImageProviderImpl(account: Option[Account], settings: SystemSettings)
|
||||
extends AvatarImageProvider with RequestCache {
|
||||
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
|
||||
override def getSystemSettings()(implicit context: app.Context): SystemSettings = settings
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user