Forum: Ruby on Rails unit testing with model inheritence

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.
Ff7c968ec96d769974df09dc453eb746?d=identicon&s=25 Sean Blezard (Guest)
on 2006-04-12 10:09
(Received via mailing list)
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 .
Ff7c968ec96d769974df09dc453eb746?d=identicon&s=25 Sean Blezard (Guest)
on 2006-04-12 10:21
(Received via mailing list)
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?
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2006-04-12 16:07
(Received via mailing list)
+! 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.
This topic is locked and can not be replied to.