[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: unit testing rails model validation? - why bother? what's rails best practice?

James Gray

6/11/2007 12:18:00 PM

On Jun 11, 2007, at 1:16 AM, Greg Hauptmann wrote:

> Is there any need to write unit test cases for model validation
> when such
> validation is implemented by a single rails validate_* line in the
> model?
> e.g. "validates_presence_of :email".

It doesn't have anything to do with how easy it is to implement.
It's about validating your business logic. If a client tells me, "An
email address is required," writing that test ensures I'm meeting the
specification.

It's also plenty common to add a custom validation method or two,
which generally require more than one line of code. Surely you would
want to test those.

Finally, I've occasionally had tests show an unexpected interplay of
many validation rules. Things like that are what unit tests are so
good at uncovering.

James Edward Gray II