Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests for Helper classes

- Make sure charset bug is fixed
  • Loading branch information...
commit 5b764d6fc7948d0f7f1f27cfb3e7adf4e3302893 1 parent 324f67c
@kahliburke authored
View
8 framework/test/integrationtest/app/controllers/Application.scala
@@ -52,6 +52,14 @@ object Application extends Controller {
Ok(toJson(JsObject(List("blah" -> JsString("foo")))))
}
+ def jsonWithContentType = Action {
+ Ok("{}").as("application/json")
+ }
+
+ def jsonWithContentTypeAndCharset = Action {
+ Ok("{}").as("application/json; charset=utf-8")
+ }
+
def index_java_cache = Action {
import play.api.Play.current
JCache.set("hello","world", 60)
View
2  framework/test/integrationtest/conf/routes
@@ -17,6 +17,8 @@ GET /intercepted-with controllers.JavaApi.interceptedUsingWith()
GET /intercepted controllers.JavaApi.intercepted()
GET /json controllers.Application.json()
GET /json_from_jsobject controllers.Application.jsonFromJsObject()
+GET /jsonWithContentType controllers.Application.jsonWithContentType()
+GET /jsonWithCharset controllers.Application.jsonWithContentTypeAndCharset()
GET /index_java_cache controllers.Application.index_java_cache()
GET /conf controllers.Application.conf()
GET /take-bool controllers.Application.takeBool(b: Boolean)
View
28 framework/test/integrationtest/test/ApplicationSpec.scala
@@ -45,7 +45,33 @@ class ApplicationSpec extends Specification {
}
}
-
+
+ def javaResult(result: play.api.mvc.Result) =
+ new play.mvc.Result {
+ def getWrappedResult = result
+ }
+
+ "execute json with content type" in {
+ running(FakeApplication()) {
+ val Some(result) = routeAndCall(FakeRequest(GET, "/jsonWithContentType"))
+ status(result) must equalTo(OK)
+ contentType(result) must equalTo(Some("application/json"))
+ charset(result) must equalTo(None)
+ play.test.Helpers.charset(javaResult(result)) must equalTo(null)
+ }
+ }
+
+
+ "execute json with content type and charset" in {
+ running(FakeApplication()) {
+ val Some(result) = routeAndCall(FakeRequest(GET, "/jsonWithCharset"))
+ status(result) must equalTo(OK)
+ contentType(result) must equalTo(Some("application/json"))
+ charset(result) must equalTo(Some("utf-8"))
+ play.test.Helpers.charset(javaResult(result)) must equalTo("utf-8")
+ }
+ }
+
"not serve asset directories" in {
running(FakeApplication()) {
val Some(result) = routeAndCall(FakeRequest(GET, "/public//"))
Please sign in to comment.
Something went wrong with that request. Please try again.