gswg-v2 icon indicating copy to clipboard operation
gswg-v2 copied to clipboard

testUniqueConstraint fails

Open aleksi-niiranen opened this issue 12 years ago • 2 comments

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.

aleksi-niiranen avatar Oct 19 '11 17:10 aleksi-niiranen

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")

jbowen7 avatar Jul 10 '12 00:07 jbowen7

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

jbowen7 avatar Jul 10 '12 06:07 jbowen7