开发者

GORM events not firing in integration tests

Trying to integration test Grails GORM delete on an object with beforeDelete event. Problem is that the beforeDelete event is not being fired in Integration Tests:

class ChallengeMembershipTests extends GroovyTestCase {
     void testQuitChallenge() {
      VUser user = VUser.build()
      assertNotNull("user should be saved", user.id)
      UserChalleng开发者_StackOverflow社区e challenge = UserChallenge.build(owner: user)
      assertNotNull("challenge should be saved", challenge.id)

      ChallengeMember member = ChallengeMember.build(challenge: challenge)
      println "MEMBER: ${member}"
      assertNotNull("member should be saved", member.id)
      member.delete(flush:true)        

  }
}

Relevant part of ChallengeMember:

  def beforeDelete = {
      log.info "begin deleting challenge member ${this}"
      user.removeFromChallenge_memberships(this)
      challenge?.removeFromParticipants(this)
      team?.removeFromMembers(this)
      log.info "deleting challenge member ${this}"
  }

Grails 1.3.5

Any suggestions?

Why do I care?

My tests are failing due to:

org.springframework.dao.InvalidDataAccessApiUsageException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.v.ChallengeMember#1]; nested exception is org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.v.ChallengeMember#1]

But, delete works fine from a browser, because beforeDelete is being fired.


Well, if I wrap in in a withNewSession it fires-

ChallengeMember.withNewSession {
   membership.delete(flush:true)
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜