Grails 资源控制器的测试URL映射路径
在Grails2.3及更高版本中,现在有了资源控制器的概念。但是,它们似乎不适用于Grails 资源控制器的测试URL映射路径,grails,grails-controller,Grails,Grails Controller,在Grails2.3及更高版本中,现在有了资源控制器的概念。但是,它们似乎不适用于assertUrlMappings概念 /foo (resources:"foo") 然后在url映射报告中出现以下内容: Controller: foo | GET | /foo | Action: index | GET | /foo/create | Action: create | P
assertUrlMappings
概念
/foo (resources:"foo")
然后在url映射报告中出现以下内容:
Controller: foo
| GET | /foo | Action: index
| GET | /foo/create | Action: create
| POST | /foo | Action: save
| GET | /foo/${id} | Action: show
| GET | /foo/${id}/edit | Action: edit
| PUT | /foo/${id} | Action: update
| PATCH | /foo/${id} | Action: patch
| DELETE | /foo/${id} | Action: delete
但是,在以下文件中,无法测试URL:
@TestFor(UrlMappings)
@Mock(FooController)
class FooURIReverseMappingsSpec extends Specification {
def "Ensure basic mapping operations for Foo uris"() {
expect:
assertUrlMapping(url, controller: expectCtrl, action: expectAction) {
id = expectId
}
where:
url | expectCtrl | expectAction | expectId
// Not sure why, but the resource controller generation url test does not find the real 'Foos' url
'/foo/123'|'foo'|'show'|'123'
}
}
然后,如果没有默认的操作url$controller/$action/$id(将匹配foo/show/123
),测试将无法找到生成的url
生成的错误是:
junit.framework.AssertionFailedError:url'/foo/123'与任何映射都不匹配
有没有办法测试资源URL?我知道这个问题已经问了5年多了,但为了将来参考,这个问题可能与中的问题相同
这个问题显然是由政府解决的。看起来此修复程序已合并到Grails2.5.x中