GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / web / metaclass / ChainMethodTests.groovy
blobafadf85c466b411b138f06c935bd829385c6b311
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
7 /**
8 * @author Graeme Rocher
9 * @since 1.0
11 * Created: Jun 2, 2008
13 class ChainMethodTests extends AbstractGrailsControllerTests{
15 public void onSetUp() {
16 gcl.parseClass('''
17 class TestChainController {
18 def save = {
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)
24 else {
25 chain(action:'create',model:[book:book])
29 class TestChainBook {
30 Long id
31 Long version
32 String title
34 ''')
37 void testChainMethodWithModel() {
38 def domainClass = ga.getDomainClass("TestChainBook").clazz
39 domainClass.metaClass.save = { false }
40 def controller = ga.getControllerClass("TestChainController").newInstance()
42 controller.save()
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
55 println flash