Fixtures and single table inheritance

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 , 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.

On 3/18/06, Matt T. [email protected] 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.