Grails
  1. Grails
  2. GRAILS-8742

Controller Integration test fails to update response if it's called on mutiple actions

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0 final
    • Fix Version/s: 2.0.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Grails: 2.0.0
    • Testcase included:
      yes

      Description

      TestController.groovy
      class TestController {
      
          def index() {
              render(contentType: "application/json"){
                  x = params.id
              }
          }
      
          def otherAction() {
              render(contentType: "application/json"){
                  y = params.xyz
              }
          }
      }
      
      TestControllerIntegrationTest.groovy
      class TestControllerIntegrationTest extends GroovyTestCase{
          def controller
      
          @Before
          void setUp() {
              // Setup logic here
              controller = new TestController()
          }
      
          @After
          void tearDown() {
              // Tear down logic here
          }
      
          @Test
          void testSomething() {
              controller.params.id = 1
              controller.index()
              def json = controller.response.json
              assert json.x == 1
              reset(controller)
              controller.params.xyz = 10
              //Fails here don't know why
              //Here controller.response == ""
              json = controller.response.json
              assert json.y == 10
          }
      
          public void reset(controller){
              controller.request.clearAttributes()
              controller.request.removeAllParameters()
              controller.response.reset()
          }
      }
      

        Activity

        Hide
        Raviteja added a comment - - edited

        This worked in 1.3.7 by adding

        controller.response.writer = null

        but this seems to be a read-only property in 2.0.0 and cannot be applied.

        This issues relates to GRAILS-6731

        Show
        Raviteja added a comment - - edited This worked in 1.3.7 by adding controller.response.writer = null but this seems to be a read-only property in 2.0.0 and cannot be applied. This issues relates to GRAILS-6731
        Hide
        Oliver Wahlen added a comment -

        You could try this:
        controller.response.metaClass.writer = null

        Show
        Oliver Wahlen added a comment - You could try this: controller.response.metaClass.writer = null

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development