Skip to content

Commit 1c76a0e

Browse files
committed
Applied Luis Arias' commit 9b43c3ba7f10864566f8 and added a unit test.
1 parent c7e16f7 commit 1c76a0e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/java/org/codehaus/groovy/grails/web/metaclass/ChainMethod.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ class ChainMethod {
5757

5858
UrlMappingsHolder mappings = appCtx.getBean(UrlMappingsHolder.BEAN_ID)
5959

60+
// Make sure that if an ID was given, it is used to evaluate
61+
// the reverse URL mapping.
62+
if (id) params.id = id
63+
6064
UrlCreator creator = mappings.getReverseMapping(controller, action, params)
6165
def response = webRequest.getCurrentResponse()
6266

6367
def url = response.encodeRedirectURL(creator.createURL(controller,action, params, 'utf-8'))
6468
response.sendRedirect url
6569

6670
}
67-
}
71+
}

src/test/org/codehaus/groovy/grails/web/metaclass/ChainMethodTests.groovy

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class TestChainController {
2525
chain(action:'create',model:[book:book])
2626
}
2727
}
28+
29+
def testId = {
30+
chain action: 'show', id: 5, model: [str: "Test param"]
31+
}
2832
}
2933
class TestChainBook {
3034
Long id
@@ -55,5 +59,11 @@ class TestChainBook {
5559
println flash
5660
}
5761

62+
void testChainMethodWithId() {
63+
def controller = ga.getControllerClass("TestChainController").newInstance()
64+
controller.testId()
5865

59-
}
66+
assertEquals "Test param", controller.flash.chainModel.str
67+
assertEquals "/testChain/show/5", response.redirectedUrl
68+
}
69+
}

0 commit comments

Comments
 (0)