Skip to content

Commit c073091

Browse files
committed
Initialize router.Routes class to set prefix in controllers.documentation.Router
1 parent 2960d0a commit c073091

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

test/controllers/documentation/DocumentationControllerSpec.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package controllers.documentation
22

3+
import play.api.routing.Router
34
import play.api.test._
45

56
object DocumentationControllerSpec extends PlaySpecification {
67

78
"DocumentationController" should {
89

910
"render a page" in new WithApplication with Injecting {
11+
inject[Router] // makes sure generated router.Routes class (in target folder) get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
1012
val reverseRouter: ReverseRouter = inject[ReverseRouter]
11-
val request = FakeRequest("GET", reverseRouter.page(None, "2.5.x", "Home"))
12-
val result = await(route(app, request).get)
13+
private val page: String = reverseRouter.page(None, "2.5.x", "Home")
14+
page must beEqualTo("/documentation/2.5.x/Home")
15+
val request = FakeRequest("GET", page)
16+
val result = await(route(app, request).get)
1317
result.header.status must beEqualTo(OK)
1418
}
1519

1620
"add canonical header" in new WithApplication with Injecting {
21+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
1722
val reverseRouter: ReverseRouter = inject[ReverseRouter]
1823
val request = FakeRequest("GET", reverseRouter.page(None, "2.5.x", "Home"))
1924
val result = await(route(app, request).get)
@@ -22,6 +27,7 @@ object DocumentationControllerSpec extends PlaySpecification {
2227

2328
"when switching to another version" should {
2429
"redirect to the selected version and page" in new WithApplication with Injecting {
30+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
2531
val reverseRouter: ReverseRouter = inject[ReverseRouter]
2632

2733
val request = FakeRequest("GET", reverseRouter.switch(None, "2.7.x", "Home"))
@@ -32,6 +38,7 @@ object DocumentationControllerSpec extends PlaySpecification {
3238

3339
"redirect to the selected version and home when no page is selected" in new WithApplication
3440
with Injecting {
41+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
3542
val reverseRouter: ReverseRouter = inject[ReverseRouter]
3643

3744
val request = FakeRequest("GET", reverseRouter.switch(None, "2.7.x", ""))
@@ -42,6 +49,7 @@ object DocumentationControllerSpec extends PlaySpecification {
4249

4350
"redirect to the selected version when not having a trailing slash" in new WithApplication
4451
with Injecting {
52+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
4553
val reverseRouter: ReverseRouter = inject[ReverseRouter]
4654

4755
val page = reverseRouter.switch(None, "2.7.x", "").stripSuffix("/")
@@ -54,6 +62,7 @@ object DocumentationControllerSpec extends PlaySpecification {
5462

5563
"when page not found" should {
5664
"redirect page that was renamed" in new WithApplication with Injecting {
65+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
5766
val reverseRouter: ReverseRouter = inject[ReverseRouter]
5867
// When accessing "AkkaCore" (was renamed to "ThreadPools")
5968
val request = FakeRequest("GET", reverseRouter.page(None, "2.5.x", "AkkaCore"))
@@ -64,6 +73,7 @@ object DocumentationControllerSpec extends PlaySpecification {
6473
}
6574

6675
"redirect page that was removed" in new WithApplication with Injecting {
76+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
6777
val reverseRouter: ReverseRouter = inject[ReverseRouter]
6878
val request = FakeRequest("GET", reverseRouter.page(None, "2.5.x", "PullRequests"))
6979
val result = route(app, request).get
@@ -72,6 +82,7 @@ object DocumentationControllerSpec extends PlaySpecification {
7282
}
7383

7484
"not redirect when there is no new page" in new WithApplication with Injecting {
85+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
7586
val reverseRouter: ReverseRouter = inject[ReverseRouter]
7687
val request = FakeRequest("GET", reverseRouter.page(None, "2.5.x", "DoesNotExists"))
7788
val result = route(app, request).get
@@ -81,6 +92,7 @@ object DocumentationControllerSpec extends PlaySpecification {
8192
}
8293

8394
"not redirect an existing page" in new WithApplication with Injecting {
95+
inject[Router] // makes sure router.Routes class get initialized, which injects controllers.documentation.Router and calls its withPrefix(...)
8496
val reverseRouter: ReverseRouter = inject[ReverseRouter]
8597
// AkkaCore exists for version 2.0
8698
val request = FakeRequest("GET", reverseRouter.page(None, "2.0.x", "AkkaCore"))

0 commit comments

Comments
 (0)