I am unable to figure out how to test for a controller action that does 'chain'. I would like to verify the action.
Grails: 2.4.2
Controller:
class MyController {
def index() {
}
def doesChain() {
chain action: 'index', model: [name: "my name"]
}
}
Test:
@TestFor(MyController)
class MyControllerSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "Action doing chain"() {
when:
controller.doesChain()
then:
controller.chainModel.name == "my name"
controller.actionName == "someAction" // fails as actionName == null
}
}
Testing the action name is not passing as the actionName appears to be null.
You could do something like this...
@TestFor(MyController)
class MyControllerSpec extends Specification {
void "Action doing chain"() {
when: 'an action invokes the chain method'
controller.doesChain()
then: 'the model is as expected'
// either of these should work, you don't need both...
controller.chainModel.name == "my name"
flash.chainModel.name == "my name"
and: 'the redirect url is as expected'
response.redirectUrl == '/my/index'
}
}
I hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With