Hi all
Been reading a couple of article’s and recently watched the Railscast
on Unit tests that don’t require fixtures.
While I can follow the basic examples given, I’m struggling to find a
way to test methods that call directly from the database.
For example,
In my Order.rb class, I have a class method called any_pending?
Order.any_pending? Which should return a boolean true if there are any
orders on the database that haven’t been paid.
to simplify:
Class Order
def any_pending?
find(:first, :conditions => {:status => PENDING}).any?
end
end
How can I simulate this without using fixtures?
I run into the same problem when testing methods through associations.
Batches have many orders, how can I test
Batch.first.orders.any_pending? without calling from the database?
Thanks
:S