A note on testing controllers
Integration tests will fail with a funny message…
grails testing Cannot send redirect – response is already committed
… if you forget to add a return statement to your controller action after you do a redirect – like so:
def handleLogin = {
def person = Person.findByPersonName(params.personName)
if(!person){
flash.message = "Person not found for Person-name: ${params.personName}"
redirect(action: "login")
return <------//-----//-----//-----//
}
session.person = person
redirect(controller: 'todo')
}
Note: This is a special case as program code that´s embeded into a control block like the above if-statement isn´t returning anything. So you need to be explicit and put in a return statement.
No comments yet
Leave a reply