Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfreedman/970650 to your computer and use it in GitHub Desktop.
Save rfreedman/970650 to your computer and use it in GitHub Desktop.
Spock Integration Test for Grails Controller Example
class CompoundInstanceControllerIntegrationSpec extends ControllerSpec {
static transactional = true
def "saving a new compound instance and compound"() {
setup:
controller.metaClass.message = {args -> "mockMessage"}
when:
controller.params.compound = compoundArgs
controller.params.compoundInstance = compoundInstanceArgs
controller.params.compoundNamesJson = compoundNamesJsonArg
SpringSecurityUtils.doWithAuth('superuser') {
controller.save()
}
then:
controller.redirectArgs.action == "show"
controller.redirectArgs.id > 0
def compoundInstance = CompoundInstance.load(controller.redirectArgs.id)
compoundInstance.primaryName == "one"
compoundInstance.compoundNames.size() == 3
compoundInstance.compound.chemicalName == "aChemical"
where:
compoundArgs = ['chemicalName': "aChemical"]
compoundInstanceArgs = ['programContact.id' : SecUser.findByUsername('superuser').id ]
compoundNamesJsonArg = '[["one",true,""],["two",false,""],["three",false,""]]'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment