Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added chain method to mocked controllers

  • Loading branch information...
commit 2d974c39f6142ac4c9ed52bc4a384c11784953e6 1 parent 1ec4733
Rob Fletcher authored
View
3  grails/src/java/grails/test/MockUtils.groovy
@@ -99,13 +99,16 @@ class MockUtils {
def fwdArgs = [:]
def redArgs = [:]
def renArgs = [:]
+ def chaArgs = [:]
def template = [:]
def modelAndView = [:]
clazz.metaClass.getForwardArgs = {-> fwdArgs}
clazz.metaClass.getRedirectArgs ={-> redArgs}
clazz.metaClass.getRenderArgs ={-> renArgs}
+ clazz.metaClass.getChainArgs ={-> chaArgs}
clazz.metaClass.forward = {Map map -> forwardArgs.putAll(map)}
clazz.metaClass.redirect = {Map map -> redirectArgs.putAll(map)}
+ clazz.metaClass.chain = {Map map -> chainArgs.putAll(map)}
clazz.metaClass.render = {String text -> delegate.response.writer << text}
clazz.metaClass.render = {Converter arg -> delegate.response.writer << arg.toString()}
View
16 grails/src/test/grails/test/MockUtilsTests.groovy
@@ -898,6 +898,18 @@ class MockUtilsTests extends GroovyTestCase {
assertEquals "bar", controller.redirectArgs.action
}
+ void testMockControllerChain() {
+ MockUtils.mockController(TestController)
+
+ def controller = new TestController()
+
+ controller.testChain()
+
+ assertEquals "foo", controller.chainArgs.controller
+ assertEquals "bar", controller.chainArgs.action
+ assertEquals "baz", controller.chainArgs.model.key
+ }
+
/**
* Tests that the mock session added to controllers works OK, and
* in particular that "session['attr']" and "session.attr" notation
@@ -1272,6 +1284,10 @@ class TestController {
redirect(controller: "foo", action: "bar")
}
+ def testChain = {
+ chain(controller: "foo", action: "bar", model: [key: "baz"])
+ }
+
def testSession = {
session["attr1"] = session["attr1"] + "_suffix"
session.attr2 = session.attr2 + "_suffix"
Please sign in to comment.
Something went wrong with that request. Please try again.