unit test model validations

Michael Rigart wrote:

      t.string 'name', :null => false       t.string 'address', :null => false       t.string 'zip', :null => false       t.string 'city', :null => false       t.string 'country', :null => false       t.string 'phone', :null => true       t.string 'fax', :null => true       t.string 'email', :null => false       t.integer 'status', :null => false       t.boolean 'is_root', :null => false, :default => false       t.boolean 'access_crm', :null => false, :default => false       t.boolean 'access_project', :null => false, :default => false       t.boolean 'access_dmail', :null => false, :default => false       t.boolean 'access_financial', :null => false, :default => false

Access looks like a separate table with a type.

How about, instead of retrofitting tests to existing features, you test-first the existence and behavior of this new type? Then test-first the database migration that copies your production data into it...

Hi Philip

wel I started out by trying to create my tests first, but I just got stuck so I decided to write the model validations.

Thats my biggest problem at the moment, I have never developed through TDD. And the main problem isn't realy whether to develop or test first, but how to build my tests.

The logic of my tests has to be wrong, becouse eather way, they fail.

Any help is welcome.

I suggest starting with a very simple test and get that working first. Use the debugger to find out what is going wrong if you cannot get it to behave correctly.

Colin Law wrote:

I suggest starting with a very simple test and get that working first. Use the debugger to find out what is going wrong if you cannot get it to behave correctly.

Further, if you cannot _briefly_ get the test working, comment it out and write a simpler test, maybe on another feature.

Test the models first, for example.

The goal here is breadth-first, not depth first. The more tests you write, the more "muscle memory" you develop, and the easier new tests get. You might come back to this validation problem, for example, and just knock it out easily...

Michael:

In October, I gave a quick intro to Rails with test-driven development at a local code camp. I distributed a PDF to the group that walks a newcomer through test-first development. Perhaps it would help you get a handle on how to get started.

This link contains a link to the PDF as well as a link to the finished project on github.

http://www.napcsweb.com/blog/index.php?s=code+camp&Submit=Search

Hope it helps. If you have questions, feel free to hit me up directly :slight_smile:

Hi guys.

I've been working on my skills the last couple of days. I have shown some improvements but as Colin stated, it is not something that you develop over night. It takes time and practice. But I notice that I'm making progress (maybe less then I expected, but still :slight_smile: ).

Brien, thanks for the input. I'm glad to see all the good work people make with writing information for newcomers.

Hi, (sorry for the double post).

I've been working on some standard methods to test model validations.

At this point, I can test on these validations:

* validates_presence_of * validates_length_of * validates_format_of * validates_numericality_of

But how do you test on the rest of validations if there is a way:

* validates_uniqueness_of * validates_confirmation_of * validates_acceptance_of * validates_associated * validates_exclusion_of * validates_inclusion_of * validates_each