views:

41

answers:

1

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.publicPrivacy = 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?

+2  A: 

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()
ataylor
Just to note that everything in the params list has to be marked ".toString()" e.g. ["book.boolean": true.toString()]
Daxon