Details
Description
(2.0.x branch)
It appears that in Grails 2.0.0 when using the new @TestFor annotation and declaring both the minSize and email constraints on the same field the minSize is not being validated. However, if the test class extends GrailsUnitTestCase it behaves as expected. Below are two examples which can be executed in "grails console".
Example 1: SUCCESS (Legacy)
import grails.test.GrailsUnitTestCase class Grails1PersonTest extends GrailsUnitTestCase { // "Domain" under test static class Person { Long id Long version String email static constraints = { email(email: true, minSize: 5) } } public void setUp() { super.setUp() mockDomain(Person, []) } public void testShouldAllowForMinSizeErrorToOccurWhenEmailIsInvalid() { def person = new Person(email: 'nope') assert !person.validate() def errors = person.errors.getFieldErrors('email') assert ['email.invalid', 'minSize.notmet'] == errors.code } }
Example 2: FAIL (Brand new hotness)
import grails.test.mixin.TestFor import org.junit.Test @TestFor(Person) class Grails2PersonTest { // "Domain" under test static class Person { Long id Long version String email static constraints = { email(email: true, minSize: 5) } } @Test public void shouldAllowForMinSizeErrorToOccurWhenEmailIsInvalid() { def person = new Person(email: 'nope') assert !person.validate() def errors = person.errors.getFieldErrors('email') assert ['email.invalid', 'minSize.notmet'] == errors.code } }
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
This should be fixed in the next release of grails-data-mapping. Once we have that the @Ignore annotation should be removed from the relevant tests in https://github.com/grails/grails-core/blob/master/grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/validation/TestingValidationSpec.groovy.