Fixtures and Legacy Tables

I'm trying to use an existing database for a new Rails project.

In my tests the fixture accessors are not working. If I try to access a Party fixture with "parties(:one)" I get the following error:

test_fixture(PartyTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.     /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ fixtures.rb:887:in `parties'     /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ fixtures.rb:884:in `map'     /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ fixtures.rb:884:in `parties'     ./test/unit/party_test.rb:10:in `test_fixture'     /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ testing/setup_and_teardown.rb:33:in `__send__'     /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ testing/setup_and_teardown.rb:33:in `run'

I have added the following to test_helper, without which it gets the table name wrong:

  set_fixture_class :parties => Party

My model is as follows:

class Party < ActiveRecord::Base   set_table_name :party end

After some debugging it appears to me that the @loaded_fixtures[table_name] is nil because table_name == 'parties' and not 'party'. It appears that the overridden table name is not carrying into the setup_fixture_accessors method.

Has anyone else had success using legacy tables that require a set_table_name with fixtures in Rails 2.1?

Thanks,

Mark

I'm trying to use an existing database for a new Rails project.

In my tests the fixture accessors are not working. If I try to access a Party fixture with "parties(:one)" I get the following error:

Looks like you can avoid some pain if you call your fixtures file
party.yml and use party(:one) instead of parties(:one)

Fred

Thanks Fred,

That worked. I've gone through so many iterations that I thought I'd tried that setup already.

Mark