I have the following test (which is probably more of a functional test than integration but...):
@Integration(applicationClass = Application)
@Rollback
class ConventionControllerIntegrationSpec extends Specification {
RestBuilder rest = new RestBuilder()
String url
def setup() {
url = "http://localhost:${serverPort}/api/admin/organizations/${Organization.first().id}/conventions"
}
def cleanup() {
}
void "test update convention"() {
given:
Convention convention = Convention.first()
when:
RestResponse response = rest.put("${url}/${convention.id}") {
contentType "application/json"
json {
name = "New Name"
}
}
then:
response.status == HttpStatus.OK.value()
Convention.findByName("New Name").id == convention.id
Convention.findByName("New Name").name == "New Name"
}
}
The data is being loaded via BootStrap (which admittadly might be the issue) but the problem is when I'm in the then
block; it finds the Convention
by the new name and the id
matches, but when testing the name
field, it is failing because it still has the old name.
While reading the documentation on testing I think the problem lies in what session the data gets created in. Since the @Rollback
has a session that is separate from BootStrap
, the data isn't really gelling. For example, if I load the data via the test's given
block, then that data doesn't exist when my controller is called by the RestBuilder
.
It is entirely possible that I shouldn't be doing this kind of test this way, so suggestions are appreciated.