Permalink
Browse files

Merge branch '2.2.x'

  • Loading branch information...
2 parents ae20a3c + d264df5 commit a4cb64111ecbbbe672e38ae6684f881c20e4c5bc @jeffbrown jeffbrown committed Nov 13, 2012
@@ -18,6 +18,7 @@ package org.codehaus.groovy.grails.web.plugins.support
import grails.validation.ValidationErrors
import org.codehaus.groovy.grails.web.context.ServletContextHolder
+import org.springframework.validation.FieldError
import org.springframework.web.context.support.WebApplicationContextUtils
@@ -42,8 +43,12 @@ class ValidationSupport {
def localErrors = new ValidationErrors(object, object.class.name)
def originalErrors = object.errors
for (originalError in originalErrors.allErrors) {
- if (originalErrors.getFieldError(originalError.field)?.bindingFailure) {
- localErrors.rejectValue originalError.field, originalError.code, originalError.arguments, originalError.defaultMessage
+ if(originalError instanceof FieldError) {
+ if (originalErrors.getFieldError(originalError.field)?.bindingFailure) {
+ localErrors.rejectValue originalError.field, originalError.code, originalError.arguments, originalError.defaultMessage
+ }
+ } else {
+ localErrors.addError originalError
}
}
for (prop in constraints.values()) {
@@ -252,4 +252,21 @@ class DefaultASTValidateableHelperSpec extends Specification {
isValid
0 == errorCount
}
+
+ void 'Test validate method on an object that has had values rejected with an ObjectError'() {
+ given:
+ def widget = widgetClass.newInstance()
+ widget.name = 'Joe'
+ widget.count = 2
+ widget.category = 'some category'
+
+ when:
+ widget.errors.reject 'count'
+ def isValid = widget.validate()
+ def errorCount = widget.errors.errorCount
+
+ then:
+ !isValid
+ 1 == errorCount
+ }
}

0 comments on commit a4cb641

Please sign in to comment.