//Integration Spec
import grails.test.spock.IntegrationSpec
class AuthorIntSpec extends IntegrationSpec {
void "test something"() {
given:
def author
when:
Author.withNewSession {
author = new Author(name: 'blah').save(flush: true)
}
then:
author.name == 'foo'
}
}
//Author
class Author {
String name
def beforeInsert() {
this.name = 'foo'
}
}
Also note, to use withNewSession
in events if you end up persisting any entity although above simple test would pass without specifying withNewSesion
(mentioned for brevity).
In your use case, there is no mocking involved so testing an interaction is not possible afaik, but you can assert that the value of circleValue
has updated after insert (flush), which in turn tests that beforeInsert
event is fired appropriately.