Grails:使用多个/前缀参数进行集成测试,例如 (params[“book”])

发布于 2024-09-24 19:33:57 字数 1020 浏览 1 评论 0原文

我在 nabble 此处

我正在尝试在控制器集成测试中发送参数或不同的域。 但无法让它们绑定到带有“book”前缀的域类

//正在测试的控制器操作

def saveBook = {
def book = new Book()
bindData(book, params["book"], [include: ['publicPrivacy', 'description', 'title'])
}

//集成测试 -

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()

我如何设置带有要发送到控制器的前缀的“params”以便它们绑定到域?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2024-10-01 19:33:57

为了使参数命名空间正常工作,我必须使用 org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap 用于 params 对象。例如:

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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文