【发布时间】:2014-10-10 23:08:57
【问题描述】:
在 Grails 2.3 及更高版本中,现在有资源控制器的概念。但是,它们似乎不适用于 assertUrlMappings 概念。
/foo (resources:"foo")
然后在url-mappings-report 中出现以下内容:
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' 不匹配任何映射
有没有办法测试资源网址?
【问题讨论】: