Fixtureless Unit Tests

2 views
Skip to first unread message

Gavin

unread,
Feb 17, 2009, 2:25:17 PM2/17/09
to Ruby on Rails: Talk
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?

http://blog.jayfields.com/2006/06/ruby-on-rails-unit-tests.html
http://blog.jayfields.com/2006/12/rails-activerecord-unit-testing.html

Thanks

:S
Reply all
Reply to author
Forward
0 new messages