Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - Domain objects not saving in integration test

I am following an example in the Grails In Action book. My integration test is failing because the searches in the example code are returning null references. I used a call to findAll() and now it appears my test data is not saving; all.size is coming back as zero.

void testBasicDynamicFinders() {

        new User(userId: 'glen', password: 'secret', profile: new Profile(email: '[email protected]')).save()
        new User(userId: 'peter', password: 'sesame', profile: new Profile(homepage: 'http://www.peter.com/')).save()

        def all = User.findAll()
        assertEquals 2, all.size()
}

I have tried using save(flush: true) to no avail.

I have also enclosed one of the save statements in a try...catch structure, but no exception appears to be raised.

Grails is really kicking my butt. Please help me?

like image 537
Stephan B Avatar asked Sep 17 '12 08:09

Stephan B


1 Answers

If you use

save( failOnError:true )

Then it should show you any validation errors that are preventing the domain objects from being saved :-)

like image 110
tim_yates Avatar answered Nov 06 '22 03:11

tim_yates