Grails
  1. Grails
  2. GRAILS-8320

Validation Errors Not Being Cleaned Up In Testing Environment

    Details

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

      Description

      Create an object with a validation error and run .validate(). Then fix the validation error and run .validate() again. The original validation error will still be there. The following test is failing because the object still has errors after the second call to .validate():

      import grails.persistence.Entity
      import grails.test.mixin.Mock
      import spock.lang.Specification
      
      @Mock(Person)
      class TestingValidationSpec extends Specification {
      
          void 'Test fixing a validation error'() {
              given:
                  def person = new Person(name: 'Jeff', age: 42, email: 'bademail')
                  
              when:
                  person.validate()
                  def errorCount = person.errors.errorCount
                  def emailError = person.errors.getFieldError('email')
                  
              then:
                  errorCount == 1
                  'person.email.email.error' in emailError.codes
                  
              when:
                  person.email = 'jeff.brown@springsource.com'
                  person.validate()
                  
              then:
                  !person.hasErrors()
          }
      }
      
      @Entity
      class Person {
          String name
          Integer age
          String email
          static constraints = {
              email email: true, size: 5..35
          }
      }
      
      

        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:
            Jeff Scott Brown
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development