Details
Description
In Grails 2.0M1 controller unit tests using the new mixin approach don't seem to handle the controller's returned model correctly. The 'model' property provided by the mixin is always empty. For instance:
class SomeController {
def test()
}
@TestFor(SomeController)
class SomeControllerTests {
def testModel()
}
Looking at the source of ControllerUnitTestMixin I see that it supplies the model like so:
Map getModel() {
final controller = webRequest.currentRequest.getAttribute(GrailsApplicationAttributes.CONTROLLER)
return controller?.modelAndView?.model ?: [:]
}
Adding a bit of logging to my test demonstrates that the first line of that is fine and it gets the controller, but controller.modelAndView is null. And that's where my understanding of what's really going on runs out as I don't know how modelAnd View is supposed to come into being.
Personally I think this is a showstopper and a bit of a surprise given it's covered in the 2.0M1 release notes complete with examples.
note you can workaround this by doing
def model = controller.test()
And then testing the returned map