Skip to content

Instantly share code, notes, and snippets.

@doitian
Created May 10, 2013 17:57
Show Gist options
  • Select an option

  • Save doitian/5556169 to your computer and use it in GitHub Desktop.

Select an option

Save doitian/5556169 to your computer and use it in GitHub Desktop.
Play Framework 2.1.1 Controller Test
package controllers
import org.specs2.mutable._
import play.api.libs.json.Json
import play.api.test._
import play.api.test.Helpers._
class EventsSpec extends Specification {
val jsonHeaders = Seq(
CONTENT_TYPE -> Seq("application/json"),
ACCEPT -> Seq("application/json")
)
val json = Json.toJson(Map("host" -> "127.0.0.1"))
"create" should {
"insert json to database" in new WithApplication {
val req = FakeRequest("POST", "/events", FakeHeaders(jsonHeaders), json)
val result = Events.create()(req)
status(result) must equalTo(CREATED)
contentType(result) must beSome("application/json")
contentAsString(result) must contain("$oid")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment