Aram Arabyan
Aram Arabyan

Reputation: 2359

How to test scale constraint in grails

In Grails domain class i have Field

BigDecimal grossWeight

and constraint for it

static constraints = {
      grossWeight(nullable: true, min: BigDecimal.ZERO, scale: 3)
   }

I like to have test for scale constraint but don't know how to implement it

Following not works

formxItem = new FormXItem(grossWeight: new BigDecimal("0.1234"))
assert !formxItem.validate()
assertNotNull formxItem.errors['grossWeight']

Upvotes: 3

Views: 476

Answers (1)

schmolly159
schmolly159

Reputation: 3881

According to the documentation for scale, the constraint does not register any validation errors, so it will not fail validation. Instead it sets the column's precision in the database and automatically scales down the precision of the number, if necessary.

Upvotes: 2

Related Questions