[grails-user] Trying to learn Grails best practices

by gio80on 2009-10-23T03:38:50+00:00

Hello everyone,
I am trying to develop an application of medium complexity with Grails and I
am running into walls.
I did some research but I was not able to answer all the questions I had and
I hope somebody who ran across some of these problems could give me some
insights:
1- I know the bean has a "hasErrors" method on it, and I can use
"renderErrors" to display them on a gsp, also I have seen in many books
people create "flash.message" and use it on the gui to give a user a
feedback.
What do you guys mostly use ? Since I started pushing most of the logic to
services I lost validate() from save() and I have to call validate()
independently before I call save(), but I find some hacking required to
actually have that working.
2- What do you guy use to rollBack a transaction ? I saw examples of people
throwing an IllegalStateException, I am considering making my own Messaging
Handling and my Exception, but I am not sure, where in the framework, I
could capture that and display my own error messages.
3- I was wondering if you could direct me to some good guide on how to write
Controller tests, I am having some issue with it, I dont find it too
straight forward.
thanks
--
View this message in context: http://www.nabble.com/Trying-to-learn-Grails-best-practices-tp26020488p26020488.html
Sent from the grails - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email

Re: [grails-user] Trying to learn Grails best practices

by Marc Palmeron 2009-10-23T10:57:27+00:00.

On 23 Oct 2009, at 04:38, gio80 wrote:
>
> Hello everyone,
>
> I am trying to develop an application of medium complexity with
> Grails and I
> am running into walls.
> I did some research but I was not able to answer all the questions I
> had and
> I hope somebody who ran across some of these problems could give me
> some
> insights:
>
> 1- I know the bean has a "hasErrors" method on it, and I can use
> "renderErrors" to display them on a gsp, also I have seen in many
> books
> people create "flash.message" and use it on the gui to give a user a
> feedback.
> What do you guys mostly use ? Since I started pushing most of the
> logic to
> services I lost validate() from save() and I have to call validate()
> independently before I call save(), but I find some hacking required
> to
> actually have that working.
>
If your code is in services, it is correct that your controller should
call validate() to ensure the data is good before calling the service,
IMO.
There should be no hacking required.
> 2- What do you guy use to rollBack a transaction ? I saw examples of
> people
> throwing an IllegalStateException, I am considering making my own
> Messaging
> Handling and my Exception, but I am not sure, where in the
> framework, I
> could capture that and display my own error messages.
>
See the docs for Domain Class withTransaction method and the
status.setRollbackOnly() method.
Normally you do not need to worry. If an exception occurs it will
rollback the current hibernate session - but if you have flushed the
session or called any transactional services, this default mechanism
will not roll back that data.
That's where withTransaction comes in. You use that in your controller
actions
> 3- I was wondering if you could direct me to some good guide on how
> to write
> Controller tests, I am having some issue with it, I dont find it too
> straight forward.
The best docs I know of are the user guide docs on this. What is
missing for you?
Cheers
~ ~ ~
Marc Palmer
Blog > http://www.anyware.co.uk
Twitter > http://twitter.com/wangjammer5
Grails Rocks > http://www.grailsrocks.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email

Re: [grails-user] Trying to learn Grails best practices

by Luke Daleyon 2009-10-26T00:21:07+00:00.

On 23/10/2009, at 1:38 PM, gio80 wrote:
> 3- I was wondering if you could direct me to some good guide on how
> to write
> Controller tests, I am having some issue with it, I dont find it too
> straight forward.
I feel your pain. This is not documented well.
You can either unit or integration test your controllers. Which one to
use really depends on the nature of your controller. However, I always
prefer unit tests, but will fall back to integration if there are a
lot of complex collaborators that would require significant mocking.
The docs _briefly_ mention ControllerUnitTestCase. It's just
GrailsUnitTestCase, but it preconfigures a controller instance
conventionally based on the class name. It's quite good.
The new spock plugin provides ControllerSpecification which has the
same API.
Example usage is here:
http://grails.org/plugin/spock#ControllerSpecification
That's reasonably straightforward to translate to
ControllerUnitTestCase usage.
As for integration testing controllers, this is covered reasonably
well by the Grails docs.
http://grails.org/doc/1.1/guide/9.%20Testing.html#9.2%20Integration%20Testing
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email

Re: [grails-user] Trying to learn Grails best practices

by Robert Fischeron 2009-10-26T13:49:27+00:00.
Check out Testing Labs for some API improvements and updates/clean-ups of ControllerUnitTestCase.
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog
Grails Expert Retainer Services
http://smokejumperit.com/grails-retainer/
Luke Daley wrote:
>
> On 23/10/2009, at 1:38 PM, gio80 wrote:
>
>> 3- I was wondering if you could direct me to some good guide on how to
>> write
>> Controller tests, I am having some issue with it, I dont find it too
>> straight forward.
>
> I feel your pain. This is not documented well.
>
> You can either unit or integration test your controllers. Which one to
> use really depends on the nature of your controller. However, I always
> prefer unit tests, but will fall back to integration if there are a lot
> of complex collaborators that would require significant mocking.
>
> The docs _briefly_ mention ControllerUnitTestCase. It's just
> GrailsUnitTestCase, but it preconfigures a controller instance
> conventionally based on the class name. It's quite good.
>
> The new spock plugin provides ControllerSpecification which has the same
> API.
>
> Example usage is here:
>
> http://grails.org/plugin/spock#ControllerSpecification
>
> That's reasonably straightforward to translate to ControllerUnitTestCase
> usage.
>
> As for integration testing controllers, this is covered reasonably well
> by the Grails docs.
>
> http://grails.org/doc/1.1/guide/9.%20Testing.html#9.2%20Integration%20Testing
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email

Re: [grails-user] Trying to learn Grails best practices

by Peter Ledbrookon 2009-10-26T14:11:20+00:00.
>> 3- I was wondering if you could direct me to some good guide on how to
>> write
>> Controller tests, I am having some issue with it, I dont find it too
>> straight forward.
>
> I feel your pain. This is not documented well.
Check out: http://www.manning.com/gsmith/SampleChapter7.pdf
It should help.
Peter
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email

Re: [grails-user] Trying to learn Grails best practices

by Luke Daleyon 2009-10-27T05:05:42+00:00.
Are you going to contribute these improvements back into the mainline?
On 26/10/2009, at 10:37 PM, Robert Fischer wrote:
> Check out Testing Labs for some API improvements and updates/clean-
> ups of ControllerUnitTestCase.
>
> ~~ Robert Fischer, Smokejumper IT Consulting.
> Enfranchised Mind Blog http://EnfranchisedMind.com/blog
>
> Grails Expert Retainer Services
> http://smokejumperit.com/grails-retainer/
>
>
> Luke Daley wrote:
>> On 23/10/2009, at 1:38 PM, gio80 wrote:
>>> 3- I was wondering if you could direct me to some good guide on
>>> how to write
>>> Controller tests, I am having some issue with it, I dont find it too
>>> straight forward.
>> I feel your pain. This is not documented well.
>> You can either unit or integration test your controllers. Which one
>> to use really depends on the nature of your controller. However, I
>> always prefer unit tests, but will fall back to integration if
>> there are a lot of complex collaborators that would require
>> significant mocking.
>> The docs _briefly_ mention ControllerUnitTestCase. It's just
>> GrailsUnitTestCase, but it preconfigures a controller instance
>> conventionally based on the class name. It's quite good.
>> The new spock plugin provides ControllerSpecification which has the
>> same API.
>> Example usage is here:
>> http://grails.org/plugin/spock#ControllerSpecification
>> That's reasonably straightforward to translate to
>> ControllerUnitTestCase usage.
>> As for integration testing controllers, this is covered reasonably
>> well by the Grails docs.
>> http://grails.org/doc/1.1/guide/9.%20Testing.html#9.2%20Integration%20Testing
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>> http://xircles.codehaus.org/manage_email
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email

Re: [grails-user] Trying to learn Grails best practices

by Scott Davison 2009-11-03T15:34:49+00:00.
Sorry that I'm late to the thread, but talks about ControllerUnitTestCase as well.
-s
Scott Davis
scott@thirstyhead.com
ThirstyHead: training done right
http://thirstyhead.com
On Oct 25, 2009, at 6:20 PM, Luke Daley wrote:
>
> On 23/10/2009, at 1:38 PM, gio80 wrote:
>
>> 3- I was wondering if you could direct me to some good guide on how
>> to write
>> Controller tests, I am having some issue with it, I dont find it too
>> straight forward.
>
> I feel your pain. This is not documented well.
>
> You can either unit or integration test your controllers. Which one
> to use really depends on the nature of your controller. However, I
> always prefer unit tests, but will fall back to integration if there
> are a lot of complex collaborators that would require significant
> mocking.
>
> The docs _briefly_ mention ControllerUnitTestCase. It's just
> GrailsUnitTestCase, but it preconfigures a controller instance
> conventionally based on the class name. It's quite good.
>
> The new spock plugin provides ControllerSpecification which has the
> same API.
>
> Example usage is here:
>
> http://grails.org/plugin/spock#ControllerSpecification
>
> That's reasonably straightforward to translate to
> ControllerUnitTestCase usage.
>
> As for integration testing controllers, this is covered reasonably
> well by the Grails docs.
>
> http://grails.org/doc/1.1/guide/9.%20Testing.html#9.2%20Integration%20Testing
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email