Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.1
-
Fix Version/s: None
-
Component/s: Testing
-
Labels:None
-
Testcase included:yes
Description
I have domain class Foo.groovy:
class Foo {
static constraints = {
details(nullable: true, blank: false, maxSize: 256)
}
String details
}
and unit test FooTests.groovy:
import grails.test.GrailsUnitTestCase
class FooTests extends GrailsUnitTestCase {
void setUp() {
super.setUp()
mockForConstraintsTests(Foo, [])
}
void testConstraints() {
Foo foo = new Foo(details: '')
foo.validate()
assertEquals 'blank', foo.errors['details']
}
}
Test fails with:
expected:<blank> but was:<null> junit.framework.ComparisonFailure: expected: but was: at FooTests.testConstraints(FooTests.groovy:12) at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:202) at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:146) at _GrailsTest_groovy$_run_closure1_closure19.doCall(_GrailsTest_groovy:112) at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:95) at TestApp$_run_closure1.doCall(TestApp.groovy:66) at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334) at gant.Gant$_dispatch_closure6.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:344) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:334) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.processTargets(Gant.groovy:495) at gant.Gant.processTargets(Gant.groovy:480)
If i change constraints definition to:
details(nullable: false, blank: false, maxSize: 256)
then test pass.
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
In Grails 1.3.2 I have a similar problem. When I use nullable constraint with true value and blank constratin with false value, if I try the constratins with a string with a '' value, Groovy returns a null value when you expect to recieve an empty string value.