How to check grails based params redirect
For example:
this is my controller code but i dont know how to write test cases for this in grails using Spock.
if(params.create){
redirect(action: "create", controller: "premiumFeature")
}else if(params.taxslab){
redirect(action: "create", controller: "taxSlab")
}
In this create
and taxSlab
there are buttons name
+3
source to share
1 answer
You can check redirects based on response property redirectedUrl
. Something like that:
@TestFor(MyController)
class MyControllerSpec extends Specification {
void "your test"() {
when:
def request = controller.request
request.addParameter("create", "paramvalue")
and:
controller.yourAction()
then:
response.redirectedUrl == "/premiumFeature/create"
}
}
+4
source to share