Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #144 from yamkazu/GRAILS-9922
Browse files Browse the repository at this point in the history
GRAILS-9922 - After a test of validation error, another test of delete()  was failed
  • Loading branch information
graemerocher committed Sep 3, 2013
2 parents 8029fc6 + d0a7a72 commit 492bcf1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 22 deletions.
Expand Up @@ -210,10 +210,9 @@ class HibernateGormInstanceApi<D> extends AbstractHibernateGormInstanceApi<D> {

@Override
void delete(D instance) {
def obj = instance
boolean flush = shouldFlush()
try {
instanceApiHelper.delete obj, flush
instanceApiHelper.delete instance, flush
}
catch (DataAccessException e) {
handleDataAccessException(hibernateTemplate, e)
Expand All @@ -222,15 +221,12 @@ class HibernateGormInstanceApi<D> extends AbstractHibernateGormInstanceApi<D> {

@Override
void delete(D instance, Map params) {
def obj = instance
hibernateTemplate.delete obj
if (shouldFlush(params)) {
try {
hibernateTemplate.flush()
}
catch (DataAccessException e) {
handleDataAccessException(hibernateTemplate, e)
}
boolean flush = shouldFlush(params)
try {
instanceApiHelper.delete instance, flush
}
catch (DataAccessException e) {
handleDataAccessException(hibernateTemplate, e)
}
}

Expand Down
@@ -0,0 +1,30 @@
package grails.gorm.tests

import spock.lang.Issue

class DeleteSpec extends GormDatastoreSpec {

@Issue("GRAILS-9922")
def "Test deleting an entity that has a validation error"() {
when:
def entity = new TestEntity(name: "Bob", age: 44).save(flush: true)

then:
!entity.hasErrors()
TestEntity.count() == 1

when:
entity.name = ""
entity.save(flush: true)

then:
entity.hasErrors()

when:
entity.delete(flush: true)

then:
TestEntity.count() == 0
}

}
Expand Up @@ -210,10 +210,9 @@ class HibernateGormInstanceApi<D> extends AbstractHibernateGormInstanceApi<D> {

@Override
void delete(D instance) {
def obj = instance
boolean flush = shouldFlush()
try {
instanceApiHelper.delete obj, flush
instanceApiHelper.delete instance, flush
}
catch (DataAccessException e) {
handleDataAccessException(hibernateTemplate, e)
Expand All @@ -222,15 +221,12 @@ class HibernateGormInstanceApi<D> extends AbstractHibernateGormInstanceApi<D> {

@Override
void delete(D instance, Map params) {
def obj = instance
hibernateTemplate.delete obj
if (shouldFlush(params)) {
try {
hibernateTemplate.flush(instance)
}
catch (DataAccessException e) {
handleDataAccessException(hibernateTemplate, e)
}
boolean flush = shouldFlush(params)
try {
instanceApiHelper.delete instance, flush
}
catch (DataAccessException e) {
handleDataAccessException(hibernateTemplate, e)
}
}

Expand Down
@@ -0,0 +1,30 @@
package grails.gorm.tests

import spock.lang.Issue

class DeleteSpec extends GormDatastoreSpec {

@Issue("GRAILS-9922")
def "Test deleting an entity that has a validation error"() {
when:
def entity = new TestEntity(name: "Bob", age: 44).save(flush: true)

then:
!entity.hasErrors()
TestEntity.count() == 1

when:
entity.name = ""
entity.save(flush: true)

then:
entity.hasErrors()

when:
entity.delete(flush: true)

then:
TestEntity.count() == 0
}

}

0 comments on commit 492bcf1

Please sign in to comment.