Closed graemerocher closed 9 years ago
Original Reporter: tianjianfeng Environment: Mac. Grails 2.0.0.RC1 Version: 2.0-RC1 Migrated From: http://jira.grails.org/browse/GRAILS-8248
Following the instructions for unit test for filters on http://grails.org/doc/2.0.0.RC1/guide/testing.html#unitTestingFilters
However, the withFilters closure is never called when running the test. Below is the code:
Filter class:
{code} class AuthenticationFilters { def filters = { create(controller:'openAm', action:'create') { before = { if (params.username == '') { render (status: HttpServletResponse.SC_BAD_REQUEST) return false } } } {code}
Controller unit test
{code} @TestMixin(GrailsUnitTestMixin) @TestFor(OpenAmController) @Mock (AuthenticationFilters) class OpenAmControllerTests { @Test void testCreateActionIsFiltered() { withFilters(action: "create") { println 'hello' controller.params.username = '' controller.create()
} assert 400 == response.status
} } {code}
graemerocher said: I attached an application demonstrating the filter testing is working in 2.0 RC1
Original Reporter: tianjianfeng Environment: Mac. Grails 2.0.0.RC1 Version: 2.0-RC1 Migrated From: http://jira.grails.org/browse/GRAILS-8248
Following the instructions for unit test for filters on http://grails.org/doc/2.0.0.RC1/guide/testing.html#unitTestingFilters
However, the withFilters closure is never called when running the test. Below is the code:
Filter class:
{code} class AuthenticationFilters { def filters = { create(controller:'openAm', action:'create') { before = { if (params.username == '') { render (status: HttpServletResponse.SC_BAD_REQUEST) return false } } } {code}
Controller unit test
{code} @TestMixin(GrailsUnitTestMixin) @TestFor(OpenAmController) @Mock (AuthenticationFilters) class OpenAmControllerTests { @Test void testCreateActionIsFiltered() { withFilters(action: "create") { println 'hello' controller.params.username = '' controller.create()
} } {code}