Forum: Ruby on Rails Fixtureless Unit Tests

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gavin (Guest)
on 2009-02-17 21:25
(Received via mailing list)
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?


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?


This topic is locked and can not be replied to.