We are in GroovyMag! Buy it now and read the article!

Me and a buddy of mine have had a groovy piece published in GroovyMag (http://www.groovymag.com/)

This is in the October Issue of the popular Grails and Groovy magazine – http://www.groovymag.com/main.issues.description/id=50/

The article deals with “Internationalizing JavaScript in Grails” and describes how to achieve dynamic internationalization in JavaScript files (in a Grails based setup).

Hope it helps someone out there!

(Let me know in the comments if you read it and it helped you!)

 

Cheers!!

Chandan L.

Grails: Integration Tests fails after Unit test, but pass when executed individually

Grails’  Spock’s Test framework is awesome man. It gives you hell lot of things that would make life easier for developers.

Usually in my project I use src/groovy/SessionUtils class for doing all session related stuff. This practice helps other developers to debug/understand where “session” is being accessed throughout the app.

While writing unit test case for controllers, sometimes I need to mock “SessionUtils'” methods using meta programming. For example:

SessionUtils.metaClass.static.getCurrentLoggedInUser = {
new User(name:’John’)
}

I changed the definition of static method getCurrentLoggedInUser() of SessionUtils class for unit test case only. But, my integration test cases started failing since Grails uses the same JVM for executing unit and integration tests(when not executed individually).

Now, how to deal with this type of situation. Thanks to Grails, it gives you registerMetaClass () method which you can use in the setup block of the method and all the meta magic would roll back after completion of every test case.

Usage:

registerMetaClass (SessionUtils)

SessionUtils.metaClass.static.getCurrentLoggedInUser = {
new User(name:’John’)
}

Hope it helps!!!

Cheers!!

 

PS: This fix is for Grails 1.3.x versions