Closed abhishek-nexthoughts closed 3 years ago
failOnError: true
is supposed to cause an exception to be thrown if any domain constraints are violated. Are you saying that isn't happening?
See the project at https://github.com/jeffbrown/abhishekissue11768.
package abhishekissue11768
class Person {
String firstName
static constraints = {
firstName matches: /[A-Z].*/
}
}
package abhishekissue11768
import grails.gorm.transactions.Transactional
@Transactional
class PersonService {
Person savePerson(String name) {
new Person(firstName: name).save(failOnError: true)
}
}
package abhishekissue11768
import grails.testing.gorm.DataTest
import grails.testing.services.ServiceUnitTest
import grails.validation.ValidationException
import spock.lang.Specification
class PersonServiceSpec extends Specification implements ServiceUnitTest<PersonService>, DataTest {
Class<?>[] getDomainClassesToMock() {
[Person]
}
void "test a valid name"() {
when:
service.savePerson 'Jeff'
then:
noExceptionThrown()
}
void "test an invalid name"() {
when:
service.savePerson 'jeff'
then:
thrown(ValidationException)
}
}
Those tests pass. Is this code representative of what you are trying to do?
FYI... The whole description of the problem was in the title of this issue. I have shortened the title and pasted the original title into the body of the question.
Yes.It is not producing an error.the domain is showing updated.But not reflected over DB
Yes.It is not producing an error.the domain is showing updated.
If you can share a sample app which demonstrates how to trigger the problematic behavior, that would be helpful.
Please feel free to reopen once you share a sample application.
I am using Grails 4.0.4.I have created a normal domain and trying to update in a transactional service with flush true.It is not generating any error while using failOnError:true.Not able to find any way to fix that,neither cause of it.Please Let me know what I am missing.