Forum: Ruby on Rails fixture fails when default table name not used

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.
sam (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
peter.j.donald (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Hi,

Try using the following to define fixtures

class UserReqTest < Test::Unit::TestCase
  fixtures :users_req
sam (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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

CHEERS> SAM
Dan (Guest)
on 2005-12-15 04:19
sam wrote:
> 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
>
> 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
This topic is locked and can not be replied to.