Grails
  1. Grails
  2. GRAILS-7969

redirectArgs no longer available for controller unit tests

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0-M1
    • Fix Version/s: None
    • Component/s: Testing
    • Labels:
      None

      Description

      redirectArgs is no longer available in controller unit tests for Grails 2.0. Instead response.redirectedUrl seems to be the way forward (that's all that is mentioned in the docs). However this means that the test is necessarily also testing the UrlMappings as well as the controller. Personally I would like to see the return of redirectArgs and consider it a bug that it has gone away - though clearly whether it's a bug or an improvement is open to interpretation. It will break existing tests and make them harder and more confusing to fix when people move to 2.0, which I think is good reason to get it working again.

        Issue Links

          Activity

          Hide
          Paul Boocock added a comment -

          It would also be useful to have forwardArgs available again. You can use response.forwardedUrl, but the format is a bit strange - something like /grails/<controllerName>/<actionName>.dispatch?id=<id>.

          Show
          Paul Boocock added a comment - It would also be useful to have forwardArgs available again. You can use response.forwardedUrl, but the format is a bit strange - something like /grails/<controllerName>/<actionName>.dispatch?id=<id>.
          Hide
          Brian Saville added a comment -

          The big question in my mind is - does this really test URL mappings as well? The application doesn't start in unit tests, so I'm not sure this is actually hitting the URL mappings at all. I would be curious to try with an "odd" URL mapping, if it just resolves to "controller/action/id".

          Show
          Brian Saville added a comment - The big question in my mind is - does this really test URL mappings as well? The application doesn't start in unit tests, so I'm not sure this is actually hitting the URL mappings at all. I would be curious to try with an "odd" URL mapping, if it just resolves to "controller/action/id".
          Hide
          Brian Saville added a comment -

          I can confirm that as far as my testing goes, it simply uses /controllerName/actionName and not any URL mappings. This is not bad at all to use for tests.

          Show
          Brian Saville added a comment - I can confirm that as far as my testing goes, it simply uses /controllerName/actionName and not any URL mappings. This is not bad at all to use for tests.
          Hide
          Eliot Sykes added a comment -

          Potential workaround to put in a redirect test in the meantime:

          controller.metaClass.redirect =

          { Map args -> controller.metaClass.redirectArgs = args }
          Show
          Eliot Sykes added a comment - Potential workaround to put in a redirect test in the meantime: controller.metaClass.redirect = { Map args -> controller.metaClass.redirectArgs = args }
          Hide
          Magno Machado Paulo added a comment -

          Here (Grails 2.2.2), the redirectedUrl IS affected by url mappings. This renders redirectedUrl almost useless for controller integration tests, as a change on a completely unrelated thing (url mappings) could potentialy break all of the tests.

          As you can redirect() inside the controller without worrying about url mappings, you should also be able to test the controller without worrying about url mappings too

          Show
          Magno Machado Paulo added a comment - Here (Grails 2.2.2), the redirectedUrl IS affected by url mappings. This renders redirectedUrl almost useless for controller integration tests, as a change on a completely unrelated thing (url mappings) could potentialy break all of the tests. As you can redirect() inside the controller without worrying about url mappings, you should also be able to test the controller without worrying about url mappings too

            People

            • Assignee:
              Unassigned
              Reporter:
              Sam Carr
            • Votes:
              12 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Last Reviewed:

                Development