Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0-M2
-
Fix Version/s: 2.0-RC1
-
Component/s: Controllers, Persistence, Testing
-
Labels:
-
Environment:Fedora 14, JDK 1.6.0_22
Description
When unit testing a controller whose @Mock'd domain contains a beforeInsert() or beforeUpdate() method, the much anticipated Grails 2.0 in-memory GORM implementation breaks on all dynamic finders.
Test app is attached, 3 files:
User
UserController
UserControllerSpec (buildconfig has spock snapshot reference)
running "test-app unit: com.test.UserControllerSpec" shows the problem
and a successful find that should fail (since beforeInsert() MD5 encodes the password):
println User.findByEmailAndPassword('abc@123.com', 'blah')
confirms the bug
Please let me know when this can be fixed, many unit tests are failing due to this unexpected behavior. in-memory GORM is such an awesome feature but I'm driving with the parking brake on right now ;-(
-
Hide
- error.zip
- 01/Oct/11 8:32 AM
- 110 kB
- Krzysztof Cygan
-
- show/.classpath 0.7 kB
- show/.project 0.5 kB
- show/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- show/application.properties 0.1 kB
- show/grails-app/conf/BootStrap.groovy 0.1 kB
- show/grails-app/conf/BuildConfig.groovy 2 kB
- show/grails-app/conf/Config.groovy 4 kB
- show/grails-app/conf/DataSource.groovy 1 kB
- show/grails-app/.../spring/resources.groovy 0.0 kB
- show/grails-app/conf/UrlMappings.groovy 0.2 kB
- show/grails-app/.../Entrepreneur.groovy 0.2 kB
- show/grails-app/.../Entrepreneur.groovy~ 0.2 kB
- show/grails-app/domain/Role.groovy 0.2 kB
- show/grails-app/domain/Role.groovy~ 0.3 kB
- show/grails-app/domain/User.groovy~ 0.9 kB
- show/grails-app/i18n/messages.properties 3 kB
- show/.../messages_cs_CZ.properties 3 kB
- show/grails-app/.../messages_da.properties 3 kB
- show/grails-app/.../messages_de.properties 4 kB
- show/grails-app/.../messages_es.properties 3 kB
- show/grails-app/.../messages_fr.properties 2 kB
- show/grails-app/.../messages_it.properties 2 kB
- show/grails-app/.../messages_ja.properties 4 kB
- show/grails-app/.../messages_nl.properties 3 kB
- show/.../messages_pt_BR.properties 3 kB
- show/.../messages_pt_PT.properties 3 kB
- show/grails-app/.../messages_ru.properties 4 kB
- show/grails-app/.../messages_sv.properties 3 kB
- show/grails-app/.../messages_th.properties 5 kB
- show/.../messages_zh_CN.properties 2 kB
-
Hide
- test.zip
- 01/Oct/11 5:08 AM
- 871 kB
- James Lang
-
- test/.classpath 4 kB
- test/.project 0.9 kB
- test/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- test/.../org.eclipse.wst.common.project.facet.core.xml 0.1 kB
- test/application.properties 0.2 kB
- test/grails-app/conf/BootStrap.groovy 0.1 kB
- test/grails-app/conf/BuildConfig.groovy 2 kB
- test/grails-app/conf/Config.groovy 4 kB
- test/grails-app/conf/DataSource.groovy 1 kB
- test/grails-app/conf/UrlMappings.groovy 0.2 kB
- test/grails-app/.../spring/resources.groovy 0.0 kB
- test/grails-app/.../KommandController.groovy 0.7 kB
- test/grails-app/.../UserController.groovy 0.5 kB
- test/grails-app/domain/.../test/User.groovy 0.2 kB
- test/grails-app/i18n/messages.properties 3 kB
- test/.../messages_cs_CZ.properties 3 kB
- test/grails-app/.../messages_da.properties 3 kB
- test/grails-app/.../messages_de.properties 4 kB
- test/grails-app/.../messages_es.properties 3 kB
- test/grails-app/.../messages_fr.properties 2 kB
- test/grails-app/.../messages_it.properties 2 kB
- test/grails-app/.../messages_ja.properties 4 kB
- test/grails-app/.../messages_nl.properties 3 kB
- test/.../messages_pt_BR.properties 3 kB
- test/.../messages_pt_PT.properties 3 kB
- test/grails-app/.../messages_ru.properties 4 kB
- test/grails-app/.../messages_sv.properties 3 kB
- test/grails-app/.../messages_th.properties 5 kB
- test/.../messages_zh_CN.properties 2 kB
- test/grails-app/views/error.gsp 0.3 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Additionally, when attempting to update a domain instance that contains a beforeInsert/Update, the instance-to-update must be wrapped in a withNewSession {} block, otherwise unit test fails with:
"No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"
first 2 stacktrace lines:
at org.grails.datastore.gorm.InstanceMethodInvokingClosure.call(GormEnhancer.groovy:241)
at com.foo.User.beforeUpdate(User.groovy:34) // does isDirty('password') check prior to encoding
When same page with same data is loaded via web browser, everything works as expected.
Reset r = Reset.findByKey(key)
if(r) {
User u = User.get(r.user.id)
u.password = r.password
User.withNewSession { // withNewSession should not be required here
if(!u.save(flush:true, validate:false))
}
i18n 'reset password success'
redirect controller:'reset'
}
@James - I'm not sure i understand that, since Hibernate is not used for unit tests
A sample app that might be related with problem, new gorm finders are not working in unit test