Announcing the “Navigation” Plugin for Grails
Another plugin release… this time thanks to help from Andreas Arledal on the CSS front.
The Navigation Plugin gives you site navigation menus by convention. You just define a property in your controllers to determine what actions are shown and in what groups.
There is even a default styling of neutral “silver” buttons that you can use, or override the CSS easily, or use tags to render the items any way you like.
Part of the motivation for this is that if we can establish a “de facto” convention for navigation info, then plugins will be able to use it, to have functionality that just automatically “pops up” in your existing application.
Anyway now when you are prototyping your apps you can just add “static navigation = true” to your controllers, and add <nav:render/> to your GSP layout… and away you go!
Enjoy!
Functional testing in Grails just got a bit sexier
Ok so here’s the 1.0 release in the spirit of “don’t worry be crappy” (can’t use that phrase enough these days) of a new functional testing plugin for Grails.
Actually its far from crappy already.
I have developed this partly as part of my work for my generous client Historic Futures Ltd. who agreed to open source this.
I plan to continue improving and maintaining it personally. It’s surely a bit rough around the edges but the benefits should be pretty obvious to those who use it.
So what are you waiting for? Run:
grails install-plugin functional-test
…but in a nutshell it is HTTP testing with HtmlUnit under the hood but the rest is pure groovy smarts, leveraging standard JUnit.
Example:
import functionaltestplugin.*
class TwitterTests extends FunctionalTestCase {
void testSearch() {
get('http://www.twitter.com')
click "Search"
assertStatus 200
assertContentContains "search"
form('searchForm') {
q = "#grails"
click "Search"
}
assertStatus 200
assertContentContains "#grails"
}
}
What’s special about this?
- Simplicity and “elasticity” by default = less fragile functional tests as a result
- Simple compact DSL/methods to learn – it tries to “do the right thing”. Let’s face it writing tests is really boring.
- Ability to get/post directly without browsing to a page first. eg REST testing
- No .properties configs
…and one more thing URL stacktrace. When a test fails the report includes a stack of the URLs at the point of failure. The xxx-out.txt file contains request parameters+headers, content received etc. This feature will be expanded in future to allow a proper request/response chain autopsy.
Caveats – things I definitely want to sort out pronto:
- currently test output is a bit ropey, I would like to do much nicer stuff with custom output xml and rendering
- no simple way to set post body
- no simple way to parse out json/xml responses yet
All this and more will come, with your support! Contribs also welcome!
ENJOY!
Grails mail plugin 0.4 released, as well as the first “Grails Rocks” screencast
I released version 0.4 of the grails-mail plugin in the Grails plugin repo the other day, but have not posted about it as I’ve been busy working on-site. I’ve also been putting together a screencast that shows how to use the plugin in the most basic scenario and also render content from GSPs from within services.
To install the plugin, which adds support for rendering the mail body from a GSP from within a controller, service or job, run: grails install-plugin mail
Full docs for the mail plugin are here.
To view the “Using the Grails mail plugin” screencast, click on the thumbnail or go to the fledgling “Grails Rocks” page.
This is the first Grails Rocks screencast, but I hope to do many more. The next one is already planned, for the forthcoming release of the Email Confirmation plugin – which was dependent on this mail plugin 0.4 release.
Latest Grails-mail plugin SVN commits fix GSP view rendering
The other day I committed some further improvements to the experimental email body rendering from GSP views. There is no release of grails-mail with this code in, you need to manually svn checkout and build it from the grails-plugins SVN repo.
Anyway, the fixes allow you to render email body GSPs where the GSP may live in a plugin, or be overriden by your app. To do this, you have to specify the plugin name when rendering the body of the mail – this is required because there’s currently no way Grails can know where the view might be as the contents of plugin view trees are not merged with the app view tree. I can see scope for a future improvement in Grails core, to add all plugin view paths to the resource search paths during development, and shipping a single merged views/ tree within .WAR files built by Grails.
So here’s how you render a mail body from a view in a controller with grails-mail installed:
sendMail {
to "test@somewhere.com"
subject "Hello"
body(view:'/something/mailbody1.gsp',
plugin:'my-great-plugin')
}
This will try to locate the view in:
<app>/grails-app/views/something/mailbody1.gsp
but if it can’t find it, will try:
<app>/plugins/my-great-plugin-<vernum>/grails-app/views/something/mailbody1.gsp
Also these commits fix GSP taglibs in email bodies. Previously they’d appear in the HTML response of the controller ooops… now they appear in the body of the mail as expected.




















