The UrBlog

John's Ramblings about Software Development

Unit Testing With the OneTimeData Plugin

The OneTimeData plugin is handy when flash doesn’t work for you. I recently had to use it in an application that required an extra redirect between controller actions. The OneTimeData plugin does not come with any unit testing assistance, so I created a simple mixin that adds the OneTimeData methods to a controller under test and backs them with a mock map on the spec to make it easy to access what the controller passed. The following class creates the mixin.

Using it requires two steps: 1) Add the mixin using the @TestMixn annotation and 2) call mockOneTimeData passing in the spec and the controller.

If anyone knows of a way to capture the spec and controller inside the mixin, please comment. Thanks!