1 package org
.codehaus
.groovy
.grails
.web
.metaclass
3 import org
.codehaus
.groovy
.grails
.web
.servlet
.mvc
.AbstractGrailsControllerTests
4 import org
.codehaus
.groovy
.grails
.web
.servlet
.GrailsFlashScope
5 import grails
.util
.MockHttpServletResponse
8 * @author Graeme Rocher
11 * Created: Jun 2, 2008
13 class ChainMethodTests
extends AbstractGrailsControllerTests
{
15 public void onSetUp() {
17 class TestChainController {
19 def book = new TestChainBook(params)
20 if(!book.hasErrors() && book.save()) {
21 flash.message = "Book ${book.id} created"
22 redirect(action:"show",id:book.id)
25 chain(action:'create
',model:[book:book])
37 void testChainMethodWithModel() {
38 def domainClass
= ga
.getDomainClass("TestChainBook").clazz
39 domainClass
.metaClass
.save
= { false }
40 def controller
= ga
.getControllerClass("TestChainController").newInstance()
44 def flash
= controller
.flash
46 assert flash
.chainModel
.book
48 def id
= System
.identityHashCode(flash
.chainModel
.book
)
50 assert flash
.chainModel
[GrailsFlashScope
.ERRORS_PREFIX
+id
]
52 org
.springframework
.mock
.web
.MockHttpServletResponse response
= controller
.response
54 assertEquals
'/testChain/create', response
.redirectedUrl