gswg-v2
gswg-v2 copied to clipboard
testUniqueConstraint fails
UserTests testUniqueConstraint junit.framework.AssertionFailedError: null junit.framework.AssertionFailedError: junit.framework.AssertionFailedError: null at UserTests.testUniqueConstraint(UserTests.groovy:38)
Any ideas what causes this or how to fix it? I can't see anything wrong with the code.
In the Second Ed of the pdf at:
110 | GETTING STARTED WITH GRAILS -SECOND EDITION
Add this test to UserTests:
void testUniqueConstraint(){
def jdoe = new User(login:"jdoe")
def admin = new User(login:"admin")
mockDomain(User, [jdoe, admin])
The instances of jdoe and admin require a password since the constraints on the domain class "User" dictated "password(blank:false,password:true)"
so just change the following lines: def jdoe = new User(login:"jdoe") def admin = new User(login:"admin")
to: def jdoe = new User(login:"jdoe", password:"1234") def admin = new User(login:"admin",password:"1234")
Also, sorry forgot to add this:
def badUser = new User(login:"jdoe",password:"1234")
Furthermore, I found that with grails 2.0.4 I need to add:
mockForConstraintsTests(User)
for the:
assertEquals 'unique', badUser.errors['login'] to return True