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

Chapter 3 listing 3.3 Saving and retrieving a domain object for the database #27

Closed
mlhart58 opened this issue Jun 21, 2013 · 2 comments

Comments

@mlhart58
Copy link

Listing is as follows:
Listing 3.3 Saving and retrieving a domain object from the database
package com.grailsinaction
import spock.lang.*
import grails.plugin.spock.*
class UserIntegrationSpec extends IntegrationSpec { #1
def "Saving our first user to the database"() {
given: "A brand new user"
def joe = new User(loginId: 'joe', password: 'secret',
homepage: 'http://www.grailsinaction.com')
when: "the user is saved" joe.save() #2
then: "it saved successfully and can be found in the database"
joe.errors.errorCount == 0 #3
joe.id != null #4
User.get(joe.id).userId == joe.userId #5
}
}

Last line should be:
User.get(joe.id).loginId == joe.loginId #5


test-app output before and after the above correction:

| Compiling 1 source files....
| Compiling 1 source files.....
| Running 1 spock test... 1 of 1
| Failure: Saving our first user to the database(com.grailsinaction.UserIntegrationSpec)
| groovy.lang.MissingPropertyException: No such property: userId for class: com.grailsinaction.User
at com.grailsinaction.UserIntegrationSpec.Saving our first user to the database(UserIntegrationSpec.groovy:19)
| Completed 1 spock test, 1 failed in 602ms
| Tests FAILED - view reports in C:\netscripts\smcccd\hubbub\target\test-reports

| Compiling 1 source files.....
| Compiling 1 source files.....
| Completed 1 spock test, 0 failed in 378ms
| Tests PASSED - view reports in C:\netscripts\smcccd\hubbub\target\test-reports

@mlhart58
Copy link
Author

You made the same mistake in listing 3.14 as well. Using "userId:" instead of "loginId:"

@pledbrook
Copy link
Contributor

Yes, there are still several references to 'userId' in the MEAP. I have updated the manuscripts for chapters 3 & 6. Chapter 11 is already fixed, but that's not managed to get into the MEAP yet.

Thanks for the report.

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