Reputation: 1
We are trying to upgrade a existing Grails 1.x application from 1.x to 2.x (current using 2.2.1). One unit test is failing and I am stuck. Here is what the test is doing...
Service -
def saveSomeData(myDomain) {
return myDomain.save(flush:true)
}
Service Test -
void testShouldSaveAndReturnTrue() {
def myDomainEmc = new ExpandoMetaClass(MyDomain)
myDomainEmc.save = {flush -> true}
myDomainEmc.initialize()
myDomainEmc.metaClass = myDomainEmc
assertTrue myTestService.saveSomeData(myDomainEmc)
}
Upvotes: 0
Views: 2378
Reputation: 66059
From the error message, it looks like save()
is being called somewhere without any arguments. Try adding a no-arg save()
method:
myDomainEmc.save = {-> true}
Also, I'd recommend using the Grails 2 @Mock
annotation for mocking domain objects to save having to handle all the possible method calls with an ExpandoMetaClass
.
Upvotes: 3