|
| 1 | +package controllers |
| 2 | + |
| 3 | +import play.api.mvc._ |
| 4 | +import play.api.i18n._ |
| 5 | +import org.scalatestplus.play._ |
| 6 | +import org.scalatestplus.play.guice.GuiceOneAppPerTest |
| 7 | +import play.api.http.FileMimeTypes |
| 8 | +import play.api.test._ |
| 9 | +import play.api.test.Helpers._ |
| 10 | +import play.api.test.CSRFTokenHelper._ |
| 11 | + |
| 12 | +import scala.concurrent.ExecutionContext |
| 13 | + |
| 14 | +/** |
| 15 | + * $model;format="Camel"$ form controller specs |
| 16 | + */ |
| 17 | +class $model;format="Camel"$ControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting { |
| 18 | + |
| 19 | + // Provide stubs for components based off Helpers.stubControllerComponents() |
| 20 | + class StubComponents(cc:ControllerComponents = stubControllerComponents()) extends MessagesControllerComponents { |
| 21 | + override val parsers: PlayBodyParsers = cc.parsers |
| 22 | + override val messagesApi: MessagesApi = cc.messagesApi |
| 23 | + override val langs: Langs = cc.langs |
| 24 | + override val fileMimeTypes: FileMimeTypes = cc.fileMimeTypes |
| 25 | + override val executionContext: ExecutionContext = cc.executionContext |
| 26 | + override val actionBuilder: ActionBuilder[Request, AnyContent] = cc.actionBuilder |
| 27 | + override val messagesActionBuilder: MessagesActionBuilder = new DefaultMessagesActionBuilderImpl(parsers.default, messagesApi)(executionContext) |
| 28 | + } |
| 29 | + |
| 30 | + "$model;format="Camel"$Controller GET" should { |
| 31 | + |
| 32 | + "render the index page from a new instance of controller" in { |
| 33 | + val controller = new $model;format="Camel"$Controller(new StubComponents()) |
| 34 | + val request = FakeRequest().withCSRFToken |
| 35 | + val home = controller.$model;format="camel"$Get().apply(request) |
| 36 | + |
| 37 | + status(home) mustBe OK |
| 38 | + contentType(home) mustBe Some("text/html") |
| 39 | + } |
| 40 | + |
| 41 | + "render the index page from the application" in { |
| 42 | + val controller = inject[$model;format="Camel"$Controller] |
| 43 | + val request = FakeRequest().withCSRFToken |
| 44 | + val home = controller.$model;format="camel"$Get().apply(request) |
| 45 | + |
| 46 | + status(home) mustBe OK |
| 47 | + contentType(home) mustBe Some("text/html") |
| 48 | + } |
| 49 | + |
| 50 | + "render the index page from the router" in { |
| 51 | + val request = CSRFTokenHelper.addCSRFToken(FakeRequest(GET, "/$model;format="camel"$")) |
| 52 | + val home = route(app, request).get |
| 53 | + |
| 54 | + status(home) mustBe OK |
| 55 | + contentType(home) mustBe Some("text/html") |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + "$model;format="Camel"$Controller POST" should { |
| 60 | + "process form" in { |
| 61 | + val request = { |
| 62 | + FakeRequest(POST, "/$model;format="camel"$") |
| 63 | + .withFormUrlEncodedBody("name" -> "play", "age" -> "4") |
| 64 | + } |
| 65 | + val home = route(app, request).get |
| 66 | +
|
| 67 | + status(home) mustBe SEE_OTHER |
| 68 | + } |
| 69 | + } |
| 70 | +
|
| 71 | +} |
0 commit comments