# Fixtureless Unit Tests

**URL:** <https://www.ruby-forum.com/t/fixtureless-unit-tests/160570>\
**Category:** Rails\
**Created:** [February 17, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/fixtureless-unit-tests/160570 "2009-02-17T20:25:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gavin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/439d5e/32.png) [@gavin](https://www.ruby-forum.com/u/gavin)\
**Post date:** [February 17, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/fixtureless-unit-tests/160570/1 "2009-02-17T20:25:49Z")

</div>

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?

> **[Ruby on Rails Unit Tests](http://blog.jayfields.com/2006/06/ruby-on-rails-unit-tests.html)**
>
> Updated following multiple comments requesting examples and questions on where to put AR::Base subclass tests. Everyone (who reads this blog...

> **[Rails: ActiveRecord Unit Testing](http://blog.jayfields.com/2006/12/rails-activerecord-unit-testing.html)**
>
> There's been a fair amount of information posted recently on the topic of unit testing ActiveRecord::Base subclasses. Of all the infor...

Thanks

:S
