Permalink
Browse files

Merge branch 'master' of github.com:grails/grails-core

  • Loading branch information...
2 parents 0cfa276 + 4b1bc5d commit 5d8384676190e6b1b730f8a080171b593959d256 @jeffbrown jeffbrown committed May 8, 2012
@@ -63,7 +63,7 @@ public boolean supports(Class clazz) {
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void validate(Object obj, Errors errors, boolean cascade) {
- if (obj == null || !domainClass.getFullName().equals(obj.getClass().getName())) {
+ if (obj == null) {
throw new IllegalArgumentException("Argument [" + obj + "] is not an instance of [" +
domainClass.getClazz() + "] which this validator is configured for");
}
@@ -0,0 +1,72 @@
+package grails.test.mixin
+
+import grails.persistence.Entity
+import org.junit.Test
+
+/**
+ * Test for GRAILS-9010
+ */
+@Mock([AbstractCustomPropertyValue])
+class InheritanceWithValidationTests {
+
+ @Test
+ void testNewStringValue () {
+ CustomProperty property = new CustomProperty ()
+
+ AbstractCustomPropertyValue propertyValue = property.newValue ("testValue")
+ assertValid (propertyValue)
+ }
+
+ private void assertValid (def propertyValue) {
+ assert propertyValue.valid
+
+ def result = propertyValue.validate () // fails here with: java.lang.IllegalArgumentException:
+ // Argument [org.example.StringPropertyValue : null] is not an instance of
+ // [class org.example.AbstractCustomPropertyValue] which this validator is configured for
+ assert result == true
+ }
+}
+
+@Entity
+class AbstractCustomPropertyValue {
+
+ boolean valid = false
+
+ static constraints = {
+ valid (validator: validator)
+ }
+
+ static transients = ['valid']
+
+ protected static validator = { value, instance ->
+ if (!instance.valid) {
+ return 'invalid.value.for.type'
+ }
+
+ return null // returning null means valid
+ }
+}
+
+@Entity
+class CustomProperty {
+
+ public AbstractCustomPropertyValue newValue (String value) {
+ return new StringPropertyValue (value)
+ }
+}
+
+
+@Entity
+class StringPropertyValue extends AbstractCustomPropertyValue {
+
+ String stringValue
+
+ static constraints = {
+ stringValue (nullable: true)
+ }
+
+ public StringPropertyValue (String value) {
+ this.stringValue = value
+ this.valid = true
+ }
+}

0 comments on commit 5d83846

Please sign in to comment.