GrailsInAction / graina2

Source code for the 2nd edition of Grails in Action
90 stars 92 forks source link

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

Closed mlhart58 closed 11 years ago

mlhart58 commented 11 years ago

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 commented 11 years ago

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

pledbrook commented 11 years ago

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.