Grails
  1. Grails
  2. GRAILS-8434

Allowed methods are not respected in unit tests

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major 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

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              Tomasz Kalkosinski
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development