Forum: Ruby on Rails Fixtureless Unit Tests

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
648a71a35ce6e4a1c5cd63451a2a20df?d=identicon&s=25 Gavin (Guest)
on 2009-02-17 20: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?
  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-un...
http://blog.jayfields.com/2006/12/rails-activereco...

Thanks

:S
This topic is locked and can not be replied to.