# Fixtures and single table inheritance

**URL:** <https://www.ruby-forum.com/t/fixtures-and-single-table-inheritance/55240>\
**Category:** Rails\
**Created:** [March 18, 2006, 1:34pm UTC](https://www.ruby-forum.com/t/fixtures-and-single-table-inheritance/55240 "2006-03-18T13:34:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maraby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@maraby](https://www.ruby-forum.com/u/maraby)\
**Post date:** [March 18, 2006, 1:34pm UTC](https://www.ruby-forum.com/t/fixtures-and-single-table-inheritance/55240/1 "2006-03-18T13:34:53Z")

</div>

I’m wondering what the accepted method for doing unit tests on STI  
models is.

I tried to create a fixture for the class but Rails tries to load that  
data into the non-existent child table. I could create a fixture named  
for the real, parent table, but then it would be very difficult to  
test for the individual functionality and integrity of each sub-class.

I saw this page  
[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/FlexibleFixtures) , but the  
comment at the top leads me to believe that solution won’t work, and I  
would like to avoid using the linked patch to fork my Rails install  
since that sounds like more trouble than it’s worth.

## Unit testing an STI model seems like a fairly com men event, so there must be some easy way to do it. What am I missing?

-Matt T.

---

<div class="post-metadata">

**Author:** ![maraby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@maraby](https://www.ruby-forum.com/u/maraby)\
**Post date:** [March 19, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/fixtures-and-single-table-inheritance/55240/2 "2006-03-19T15:58:44Z")

</div>

On 3/18/06, Matt T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> would like to avoid using the linked patch to fork my Rails install  
> since that sounds like more trouble than it’s worth.
> 
> ## Unit testing an STI model seems like a fairly com men event, so there must be some easy way to do it. What am I missing?
> 
> -Matt T.

OK, I applied Duane’s patch linked to from the above-mentioned wiki  
page, but it too doesn’t appear to play well with STI, even when I  
manually specificy the correct table name. I e-mailed Duane about it  
to see if it was a known bug, or something I did wrong. In the  
meantime, does anybody have any pointers on how they unit test STI  
classes?

Like I said above, this task would seem to be a common one. STI  
classes especially would need a good unit testing system. I can’t be  
the first guy to run into this, so what does everybody else do in this  
situation? What obvious thing am I missing?

–  
-Matt T.
