Grails
  1. Grails
  2. GRAILS-8248

Unit test withFilters not working for grails 2.0.0.RC1

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0-RC1
    • Fix Version/s: 2.0-RC2
    • Component/s: Testing
    • Labels:
      None
    • Environment:
      Mac. Grails 2.0.0.RC1

      Description

      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:

      class AuthenticationFilters {
        def filters = {
          create(controller:'openAm', action:'create') {
            before = {
              if (params.username == '') {
                render (status: HttpServletResponse.SC_BAD_REQUEST) 
        	  return false
              }
          }
      }
      

      Controller unit test

      @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 
         }
      }
      

        Activity

        Hide
        Graeme Rocher added a comment -

        I attached an application demonstrating the filter testing is working in 2.0 RC1

        Show
        Graeme Rocher added a comment - I attached an application demonstrating the filter testing is working in 2.0 RC1
        Hide
        Graeme Rocher added a comment -

        The actual issue was that the filter testing support was swallowing exceptions. So if you had some problems in your code you would not see the exception.

        But as you can see with the attached application if your code doesn't produce an exception then the withFilters method works as expected.

        The exception swallowing problem has now been fixed with the commit:

        https://github.com/grails/grails-core/commit/fa87b29fab986fda521f6e77e7162bbb4c4ebf3f

        Show
        Graeme Rocher added a comment - The actual issue was that the filter testing support was swallowing exceptions. So if you had some problems in your code you would not see the exception. But as you can see with the attached application if your code doesn't produce an exception then the withFilters method works as expected. The exception swallowing problem has now been fixed with the commit: https://github.com/grails/grails-core/commit/fa87b29fab986fda521f6e77e7162bbb4c4ebf3f

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Jet
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development