Railsters:

Those of you who dig ActiveRecord need this:

http://www.oreillynet.com/ruby/blog/2008/09/polygamous_assert_latest.html

It shows how to write tests like this:

     t, fz = assert_latest T2, Foo do
               T2.create
               2.times{ Foo.create }
             end

     assert do
       t.id > 0     and
       fz[0].id > 0 and
       fz[1].id > fz[0].id
     end

The inner lines - T2.create etc. - represent your production code in action. 
You 
put the assert_latest around that code, and it will detect any new records of 
the given type. You can then assert the records have the fields you expect.

The assertion is "polygamous" because you can pass any list of types in. The 
original version only took one type.

This is useful for any kind of testing, but super-useful for integration tests, 
to detect large batches of new records.

Get assert_latest with the assert_efficient_sql gem.

-- 
   Phlip


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to