Mike & Zan
Thanks for the tips. I got the renderParams to work.
However, an equivalent redirectParams does not work.
I used the code examples and the Glen Smith tutorial referenced
in the GRAILS-2630 thread. But the "redirectParams.action" does not
resolve to a string, it resolves to an Object. i.e. I get the
closure# and HEX address
for the Object on a println statement. It gets worse when I place
that in an assertEquals().
Glen Smith uses the redirectParams.action in exactly the way you
suggested the
renderParams. I get the latter to work, but not the redirect
version.
setUp() {
def redirectParams = [:]
ServicerController.metaClass.redirect = { Map args -> redirectParams =
args }
mySC = new ServicerController(()
}
testUpdate() {
mySC.params.id = 15 //try retrieve a nonexistent record from DB
mySC.update.call()
assertEquals('edit", redirectParams.action)
}
This pattern works with "render" but not with "redirect". I am
watchful that
the conditionasl branch in update() under test is the correct either
"render" or
"redirect" as the testCase may be.
One other oddity: before declaring the "metaClass.render" I could
get the value of
mySC.response.redirectedUrl, but after the metaClass declaration the
redirectedUrl
returns null.
Thanks for your continued help.
Steph T
On May 15, 10:26 am, Mike Hugo <
m...@piragua.com> wrote:
> Also take a look athttp://
jira.codehaus.org/browse/GRAILS-2630which
> has several attachments including a "ControllerTestCase" that does the
> kind of thing Zan explains below and simplifies your tests by creating
> a "withController" closure you can use.
>
> Mike
>
> On May 15, 2008, at 10:17 AM, Zan Thrash wrote:
>
>
>
> > Steph,
>
> > Here is what I do for testing render code in my controllers.
>
> > Lets say I have a controller named "Foo" with a "bar" closure that
> > renders a "show" view and some model.
>
> > In my test class under the setUp():
>
> > def renderParams = [:]
> > Foo.metaClass.render = {Maps args -> renderParams = args}
>
> > This will "intercept" all of the calls on you controller to "render"
> > and dump it into your renderParams map.
>
> > Then in your actual test you can call the closure on the controller
> > and make assertions like so.
>
> > assertEquals "show", renderParams.view
> > assert "some value on the model", renderParams.model.[someObject]?.
> > [someAttribute]
>
> > Hope this helps,
>
> > Zan Thrash
>
> > On Wed, May 14, 2008 at 10:55 PM, Steph Thompson <
SPTh...@frontiernet.net
> > > > - Show quoted text -- Hide quoted text -