Consider the following code:
class User {
static constraints = {
email email: true, unique: true
token nullable: true
}
String email
String password
String token
}
@TestFor(User)
@TestMixin(DomainClassUnitTestMixin)
class UserSpec extends Specification {
def "email should be unique"() {
when: "twice same email"
def user = new User(email: "test@test.com", password: "test")
def user2 = new User(email: "test@test.com", password: "test")
then: "saving should fail"
user.save()
!user2.save(failOnError: false)
}
}
With the following configuration (part of it), application.yml:
grails:
gorm:
failOnError: true
autoFlush: true
Why user2.save(failOnError: false)doesn’t it return falsebecause it is not stored in the database?
The result of work grails test-app *UserSpec::
businesssoftware.UserSpec> email must be unique. Faulty org.spockframework.runtime.ConditionNotSatisfiedError in UserSpec.groovy: 40
When I replace user.save()with user.save(flush: true), it works.
However, the documentation at https://grails.imtqy.com/grails-doc/latest/guide/conf.html , section 4.1.3 states that:
grails.gorm.autoFlush - true, , , , save (flush: true).
grails --version:
| Grails : 3.0.2
| Groovy : 2.4.3
| JVM: 1.8.0_40
, ?