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:
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.
parties' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ fixtures.rb:884:inmap’
__send__' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ testing/setup_and_teardown.rb:33:inrun’
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
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?