Permalink
Browse files

fix for GRAILS-4344

  • Loading branch information...
1 parent 827774e commit 06c6690cf4016e05d96dbd2d79456c80746cb065 @graemerocher graemerocher committed Jul 21, 2009
@@ -135,9 +135,9 @@ class ClosureEventTriggeringInterceptor extends SaveOrUpdateEventListener implem
public boolean onPreUpdate(PreUpdateEvent event) {
def entity = event.getEntity()
-
+ def evict = false
if(shouldTrigger(entity)) {
- def result = triggerEvent(BEFORE_UPDATE_EVENT, event.entity, event)
+ evict = triggerEvent(BEFORE_UPDATE_EVENT, event.entity, event)
Mapping m = GrailsDomainBinder.getMapping(entity.getClass())
boolean shouldTimestamp = m && !m.autoTimestamp ? false : true
@@ -149,9 +149,12 @@ class ClosureEventTriggeringInterceptor extends SaveOrUpdateEventListener implem
entity."$property.name" = now
}
- return result
}
-
+
+ if(!entity.validate(deepValidate:false)) {
+ evict = true
+ }
+ return evict
}
public void onPostUpdate(PostUpdateEvent event) {
@@ -0,0 +1,63 @@
+package org.codehaus.groovy.grails.orm.hibernate
+/**
+ * @author Graeme Rocher
+ * @since 1.1
+ */
+
+public class DoNotPersistInvalidObjectTests extends AbstractGrailsHibernateTests{
+
+ protected void onSetUp() {
+ gcl.parseClass('''
+import grails.persistence.*
+
+@Entity
+class DoNotPersist {
+ String name
+
+ static constraints = {
+ name size:1..5
+ }
+}
+''')
+ }
+
+
+ void testDoNoPersistInvalidInstanceUsingDirtyChecking() {
+ def testDomain = ga.getDomainClass("DoNotPersist").clazz
+
+ def t = testDomain.newInstance(name:"bob")
+
+ assertNotNull "should have saved test instance",t.save(flush:true)
+
+ session.clear()
+
+ t = testDomain.get(1)
+ t.name = "fartooolong"
+
+ session.flush()
+ session.clear()
+
+ t = testDomain.get(1)
+ assertEquals "bob", t.name
+ }
+
+ void testPersistValidInstanceUsingDirtyChecking() {
+ def testDomain = ga.getDomainClass("DoNotPersist").clazz
+
+ def t = testDomain.newInstance(name:"bob")
+
+ assertNotNull "should have saved test instance",t.save(flush:true)
+
+ session.clear()
+
+ t = testDomain.get(1)
+ t.name = "fred"
+
+ session.flush()
+ session.clear()
+
+ t = testDomain.get(1)
+ assertEquals "fred", t.name
+ }
+
+}

0 comments on commit 06c6690

Please sign in to comment.