Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testUniqueConstraint fails #4

Open
aleksi-niiranen opened this issue Oct 19, 2011 · 2 comments
Open

testUniqueConstraint fails #4

aleksi-niiranen opened this issue Oct 19, 2011 · 2 comments

Comments

@aleksi-niiranen
Copy link

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.

@jbowen7
Copy link

jbowen7 commented Jul 10, 2012

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
Copy link

jbowen7 commented Jul 10, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants