# Fixture fails when default table name not used

**URL:** <https://www.ruby-forum.com/t/fixture-fails-when-default-table-name-not-used/99950>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/fixture-fails-when-default-table-name-not-used/99950 "2005-11-12T12:49:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/fixture-fails-when-default-table-name-not-used/99950/1 "2005-11-12T12:49:35Z")

</div>

Hi All,

So I have a model like this (and associated users\_req in the db - legacy  
table):

class UserReq \< ActiveRecord::Base  
set\_table\_name “users\_req”  
end

and fixtures like this:

first\_user\_req:  
id: 1  
another\_user\_req:  
id: 2

called in my test class like so:

class UserReqTest \< Test::Unit::TestCase  
fixtures :user\_reqs

and gives the following error:

ActiveRecord::StatementInvalid: #42S02Table ‘discourse2\_test.user\_reqs’  
doesn’t  
exist: DELETE FROM user\_reqs

It seems that despite the model table name override the fixture is still  
using the default table name

Any insight on how to get round this greatly appreciated.

CHEERS\> SAM

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/fixture-fails-when-default-table-name-not-used/99950/2 "2005-11-12T12:49:36Z")

</div>

Hi,

Try using the following to define fixtures

class UserReqTest \< Test::Unit::TestCase  
fixtures :users\_req

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/fixture-fails-when-default-table-name-not-used/99950/3 "2005-11-12T12:49:36Z")

</div>

Hi Peter,

Thanks - that fixed it - although the .yml file name had to be changed  
too.

I’ve opened a ticket:

[http://dev.rubyonrails.com/ticket/2809](http://dev.rubyonrails.com/ticket/2809)

CHEERS\> SAM

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [December 15, 2005, 4:19am UTC](https://www.ruby-forum.com/t/fixture-fails-when-default-table-name-not-used/99950/4 "2005-12-15T04:19:26Z")

</div>

sam wrote:

> Hi Peter,
> 
> Thanks - that fixed it - although the .yml file name had to be changed  
> too.
> 
> I’ve opened a ticket:
> 
> [Peak Obsession](http://dev.rubyonrails.com/ticket/2809)
> 
> CHEERS\> SAM

I did this and the (canned) test failed.  
My setup is just like Sam’s except class and table names are different.  
I have a model class where set\_table\_name sets the legacy table name. I  
created a fixture yml file named with the actual table name and refer to  
that in my test. Nevertheless, I got an error running the test.

My class is called Externaldoc instead of UserReq. This line:  
assert\_kind\_of Externaldoc, externaldocs(:first)

Returned the following:

1. Error:  
test\_truth(ExternaldocTest):  
NoMethodError: undefined method `externaldocs' for #<ExternaldocTest:0xf68f20b8> /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.1/lib/action_controller/test_process.rb:377:in `method\_missing’  
test/unit/externaldoc\_test.rb:9:in `test\_truth’

1 tests, 0 assertions, 0 failures, 1 errors

I read the ticket you submitted and the followups to it that resulted in  
a patch. Unfortunately I was not able to install the patch without  
breaking my system. This may be because I really don’t know what I’m  
doing.

Anyway, it sounds like tests were passing for sam…what am I missing?

BTW, the problem I am trying to solve could perhaps be solved another  
way, and maybe y’all could point out that way, and then all this would  
be moot, for me at least.

I am working with a legacy postgresql database. One of the issues is  
that there are four types of data stored in the same table. Call them  
types a thru d. To get all type a rows, add a “where url is not null”  
clause to the sql. And so forth. We used to handle this in our java ORM  
(iBATIS) but since Rails uses such a different paradigm, I’m not sure  
what to do.

I want to end up with four different objects and override find\_all in  
each of them so that calling find\_all on, say the b object, returns all  
rows that match a certain SQL where clause. But so far that doesn’t seem  
to be testable.

I am open to suggestions about what might better. Thanks!  
D
