# Unit testing with model inheritence

**URL:** <https://www.ruby-forum.com/t/unit-testing-with-model-inheritence/57596>\
**Category:** Rails\
**Created:** [April 12, 2006, 10:09am UTC](https://www.ruby-forum.com/t/unit-testing-with-model-inheritence/57596 "2006-04-12T10:09:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [April 12, 2006, 10:09am UTC](https://www.ruby-forum.com/t/unit-testing-with-model-inheritence/57596/1 "2006-04-12T10:09:31Z")

</div>

Having jotted down some models, with some inheritence I tried to run  
some  
unit tests. After waiting for rake test\_units to run I got a rake of  
errors  
(if you’ll forgive the play on words). The errors were to do with  
unknown  
tables in the tear down stage. The unknown tables corresponded to  
sub-types  
where single table inheritence was used. In other words, these tables  
_shouldn’t_ exist. Any thoughts? I can only hope there is another  
beginner’s  
error lurking in my project.

Sean .

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [April 12, 2006, 10:21am UTC](https://www.ruby-forum.com/t/unit-testing-with-model-inheritence/57596/2 "2006-04-12T10:21:53Z")

</div>

One workaround seems to be to delete the generated fixtures for the  
subtypes  
and change the unit tests for the subtypes to use the top level parent’s  
fixtures. This effectively says the fixture file for the parent will  
have  
fixtures for all the different subtypes. Consequently, the teardown will  
only tear down the table for the parent, rather than trying to delete  
entries from phantom tables.

A reasonable workaround but it would be nice if the model generator  
(which  
scaffolds the tests) could catch this nuance, perhaps only generating  
test  
classes for model objects that directly extend the active record stuff?

---

<div class="post-metadata">

**Author:** ![seanb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@seanb](https://www.ruby-forum.com/u/seanb)\
**Post date:** [April 12, 2006, 4:07pm UTC](https://www.ruby-forum.com/t/unit-testing-with-model-inheritence/57596/3 "2006-04-12T16:07:29Z")

</div>

+! for Sean’s workaround.

In fact, I actually don’t generate models for my subclasses… I just do  
them by hand. When I only have one, I use the parent class’s unit test  
file  
to test the subclasses.
