I’d like to write some tests for delete() in Grails. These need to be integration tests because they require the database with hibernate.
It would be nice to be able to write tests to figure out when delete() fails due to foreign key constraints.
Example:
void testDeleteMedia() {
def playlist = new Playlist(name:'list1')
.addToSongs(new Song(name:'song1'))
.save()
playlist.delete()
assertFalse Playlist.exists(playlist.id)
// TODO: assert there no constraint failures
}
You can use:
or
The information about why the delete failed will appear when accessing the dynamic finder or the exists method.