[英]Grails 4 hasone not validating correctly
I'm working on upgrading a fairly large Grails 2.5 app to Grails 4.0.3.我正在将一个相当大的 Grails 2.5 应用程序升级到 Grails 4.0.3。 I have something similar in my domain structure to my example here.我的域结构中有与我的示例类似的内容。
package com.test
class Face {
static hasOne = [mouth: Mouth]
static constraints = {
}
}
package com.test
abstract class Mouth {
Face face
static constraints = {
}
}
package com.test
class BigMouth extends Mouth {
Integer numberOfTeeth
Boolean tonsilsRemoved
}
The behavior I expect to see when validating a face object is that it should also validate the mouth object.在验证人脸 object 时,我希望看到的行为是它还应该验证嘴 object。 So I have a test Controller set up to test that like such所以我有一个测试 Controller 设置来测试这样的
package com.test
class TestController {
def index() {
Face face = new Face()
face.mouth = new BigMouth(
face: face
)
// numberOfTeeth & tonsilsRemoved cannot be null, but are
assert !face.validate()
println 'no failure'
}
}
And a test case和一个测试用例
package com.test
import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification
class FaceSpec extends Specification implements DomainUnitTest<Face> {
def setup() {
}
def cleanup() {
}
void "test hasOneValidation"() {
when:
domain.mouth = new BigMouth(numberOfTeeth: null)
then:
!domain.validate()
}
}
However, the behavior I'm seeing is that face is valid and it is not passing the assert statement.但是,我看到的行为是 face 是有效的,它没有通过 assert 语句。 This worked for us in 2.5.这在 2.5 中对我们有用。 Another note on this test case is that If I move the BigMouth Properties to Mouth and make that a concrete class, The same test will have a face object that fails vaildation and passes the assert statement.这个测试用例的另一个注意事项是,如果我将 BigMouth 属性移动到 Mouth 并使其成为具体的 class,则相同的测试将有一个面 object 验证失败并通过断言语句。
Is this expected behavior for Grails 4.0.3 or not?这是 Grails 4.0.3 的预期行为吗? If not, am I doing something blatantly wrong here?如果没有,我在这里做错了什么吗?
Running Grails 4.0.3, Java 11, Windows 10运行 Grails 4.0.3,Java 11,Windows 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.