Grails: Integration testing with multiple/prefixed params e.g. (params["book"])
I've asked the exact same question on nabble here
I'm trying to send params or different domains in the controller integration test. But can't get them to bind to the domain class with the prefix of "book"
//Controller action being tested
def saveBook = {
def book = new Book()
bindData(book, params["book"], [include: ['publicPrivacy', 'description', 'title'])
}
//Integration Test -
def bookController = BookContoller()
//Doesn't Bind
bookController.params.publicP开发者_运维知识库rivacy = false
bookController.params.description = "Best book in the world"
bookController.params.title = "The world"
bookController.params.book.publicPrivacy = false
bookController.params.book.description = "Best book in the world"
bookController.params.book.title = "The world"
bookController.params["book"].publicPrivacy = false
bookController.params.[book.description] = "Best book in the world"
bookController.saveBook()
how do i set the "params" with the prefix to be sent to the controller so they bind to the domain?
For params namespacing to work, I've had to use a org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap
for the params object. For example:
def p = ['book.description': "Best book in the world", ...]
def request = [getParameterMap: { -> p }] as javax.servlet.http.HttpServletRequest
controller.params = new org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap(request)
controller.saveBook()
精彩评论