Skip to content

Commit

Permalink
fix for GRAILS-5669 "On a controller integration test, calling render…
Browse files Browse the repository at this point in the history
… with a GSP on a base controller results in Cannot set readonly property: modelAndView"
  • Loading branch information
graemerocher committed Jan 26, 2010
1 parent 1e103b7 commit d1504a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion grails/src/java/grails/test/MockUtils.groovy
Expand Up @@ -37,6 +37,8 @@ import org.springframework.beans.SimpleTypeConverter
import org.springframework.mock.web.MockHttpSession
import org.springframework.validation.Errors
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.servlet.ModelAndView;

import grails.validation.ValidationException

/**
Expand Down Expand Up @@ -103,7 +105,7 @@ class MockUtils {
def renArgs = [:]
def chaArgs = [:]
def template = [:]
def modelAndView = [:]
def modelAndView = new ModelAndView()
clazz.metaClass.getForwardArgs = {-> fwdArgs}
clazz.metaClass.getRedirectArgs ={-> redArgs}
clazz.metaClass.getRenderArgs ={-> renArgs}
Expand Down Expand Up @@ -227,6 +229,7 @@ class MockUtils {

clazz.metaClass.getTemplate = {-> template}
clazz.metaClass.getModelAndView = {-> modelAndView}
clazz.metaClass.setModelAndView = { ModelAndView mv -> modelAndView = mv}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions grails/src/test/grails/test/ControllerUnitTestCaseTests.groovy
@@ -1,5 +1,7 @@
package grails.test;

import org.springframework.web.servlet.ModelAndView;

/**
* Test case for {@link ControllerUnitTestCase}.
*/
Expand All @@ -25,9 +27,22 @@ class ControllerUnitTestCaseTests extends GroovyTestCase {
testCase.testCommandObject()
testCase.tearDown()
}

void testGetSetModelAndView() {
def testCase = new UnitTestControllerTestCase()
testCase.setUp()
testCase.testModelAndView()
testCase.tearDown()

}
}

class UnitTestControllerTestCase extends ControllerUnitTestCase {

void testModelAndView() {
controller.testSetModelAndView()
}

void testControllerClass() {
assertEquals UnitTestController, controllerClass
assertEquals "unitTest", controller.controllerName
Expand Down Expand Up @@ -74,6 +89,11 @@ class UnitTestController {
def index = {

}

def testSetModelAndView() {
modelAndView = new ModelAndView()
println modelAndView.viewName
}
}

class ControllerUnitTestCaseCommandObject {
Expand Down

0 comments on commit d1504a8

Please sign in to comment.