2

I have an issue where the global constraints setup in the Config are not working when running unit tests.

This is in my Config.groovy:

grails.gorm.default.constraints={
'*'(nullable:true, bindable:true)
}

in my test I have tried this:

static doWithConfig(c){
c.grails.gorm.default.constraints={
'*'(nullable:true, bindable:true)
}

and also in the setupSpec():

grailsApplication.config.grails.gorm.default.constraints={
'*'(nullable:true, bindable:true)
}

All I'm doing in my test is trying to create a domain object from a json string. Is there anything special that I should be doing to get this to work in the Unit test? This is also using the Gorm-MongoDb plugin.

  • 1
    Don't believe you can: http://stackoverflow.com/questions/2158341/grails-global-constraints – tim_yates Jun 30 '15 at 12:46
  • 1
    In this version 2.4.3 you can use the static doWithConfig(c) to set up the configuration for the tests. I verified this with Grails in another issue with Date Formatting. For some reason the globals aren't being picked up though. I thought they were for a minute, but then I realized I couldn't validate in another test. So for some reason nullable:true for all properties does not work. – Kevin Paxton Jun 30 '15 at 17:06

0 Answers0