Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-RC2
    • Component/s: Testing
    • Labels:
      None
    • Testcase included:
      yes

      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

        Hide
        Jeff Scott Brown added a comment -

        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.

        Show
        Jeff Scott Brown added a comment - 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 .

          People

          • Assignee:
            Jeff Scott Brown
            Reporter:
            Ross Niemi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development