Fix testcase.

This commit is contained in:
takezoe
2013-10-16 04:47:43 +09:00
parent da62c6181e
commit f40c7ff4fa
2 changed files with 9 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ trait AvatarImageProvider { self: RequestCache =>
s"""${context.path}/${account.userName}/_avatar""" s"""${context.path}/${account.userName}/_avatar"""
} }
} getOrElse { } getOrElse {
if(mailAddress.nonEmpty && getSystemSettings().gravatar){ if(getSystemSettings().gravatar){
s"""http://www.gravatar.com/avatar/${StringUtil.md5(mailAddress.toLowerCase)}?s=${size}""" s"""http://www.gravatar.com/avatar/${StringUtil.md5(mailAddress.toLowerCase)}?s=${size}"""
} else { } else {
s"""${context.path}/_unknown/_avatar""" s"""${context.path}/_unknown/_avatar"""

View File

@@ -41,32 +41,32 @@ class AvatarImageProviderSpec extends Specification {
"<img src=\"http://www.gravatar.com/avatar/4712f9b0e63f56ad952ad387eaa23b9c?s=20\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />" "<img src=\"http://www.gravatar.com/avatar/4712f9b0e63f56ad952ad387eaa23b9c?s=20\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
} }
"show local image for unknown user if gravatar integration is enabled" in { "show unknown image for unknown user if gravatar integration is enabled" in {
val provider = new AvatarImageProviderImpl(None, createSystemSettings(true)) val provider = new AvatarImageProviderImpl(None, createSystemSettings(true))
provider.toHtml("user", 20).toString mustEqual provider.toHtml("user", 20).toString mustEqual
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />" "<img src=\"/_unknown/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
} }
"show local image for specified mail address if gravatar integration is disabled" in { "show unknown image for specified mail address if gravatar integration is disabled" in {
val provider = new AvatarImageProviderImpl(None, createSystemSettings(false)) val provider = new AvatarImageProviderImpl(None, createSystemSettings(false))
provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual provider.toHtml("user", 20, "hoge@hoge.com").toString mustEqual
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />" "<img src=\"/_unknown/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" />"
} }
"add tooltip if it's enabled" in { "add tooltip if it's enabled" in {
val provider = new AvatarImageProviderImpl(None, createSystemSettings(false)) val provider = new AvatarImageProviderImpl(None, createSystemSettings(false))
provider.toHtml("user", 20, "hoge@hoge.com", true).toString mustEqual provider.toHtml("user", 20, "hoge@hoge.com", true).toString mustEqual
"<img src=\"/user/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" data-toggle=\"tooltip\" title=\"user\"/>" "<img src=\"/_unknown/_avatar\" class=\"avatar\" style=\"width: 20px; height: 20px;\" data-toggle=\"tooltip\" title=\"user\"/>"
} }
} }
private def createAccount(image: Option[String]) = private def createAccount(image: Option[String]) =
Account( Account(
userName = "", userName = "user",
fullName = "", fullName = "user@localhost",
mailAddress = "", mailAddress = "",
password = "", password = "",
isAdmin = false, isAdmin = false,
@@ -95,6 +95,7 @@ class AvatarImageProviderSpec extends Specification {
def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false) def toHtml(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)
(implicit context: app.Context): Html = getAvatarImageHtml(userName, size, mailAddress, tooltip) (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 getAccountByUserName(userName: String)(implicit context: app.Context): Option[Account] = account
override def getSystemSettings()(implicit context: app.Context): SystemSettings = settings override def getSystemSettings()(implicit context: app.Context): SystemSettings = settings
} }