Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 2.0-RC3
-
Fix Version/s: None
-
Component/s: Controllers, Testing
-
Labels:
-
Environment:Kubuntu linux, Intellij IDEA
-
Testcase included:yes
Description
Allowed methods are not respected in unit tests. This is a regression from RC2. Allowed methods work as respected in development and production fine. Simple scanario:
class BookController {
static allowedMethods = [index: "POST"]
def index() {
println "Method is ${request.method}"
redirect(action: "ok")
}
def ok () {
render(view: "ok")
}
}
@TestFor(BookController)
class BookControllerTests {
void testMethodGet() {
request.method = "GET"
controller.index()
println("In test, request redirectUrl is ${response.redirectUrl} and it should be null")
assert response.status == HttpServletResponse.SC_METHOD_NOT_ALLOWED
assert response.redirectUrl == null
}
void testMethodPost() {
request.method = "POST"
controller.index()
assert response.redirectUrl == "/book/ok"
}
}
Method is GET
In test, request redirectUrl is /book/ok and it should be null
| Failure: testMethodGet(rc3methodnotallowed.BookControllerTests)
| Assertion failed:
assert response.status == HttpServletResponse.SC_METHOD_NOT_ALLOWED
| | | |
| 302 false 405
org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletResponse@1b030d8
at rc3methodnotallowed.BookControllerTests.testMethodGet(BookControllerTests.groovy:16)
Issue Links
- duplicates
-
GRAILS-8426
Controller AllowedMethods in unit test not working
-
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits