Error loading fixtures with classes that set_table_name

Hi all,

I just hit a big wall involving a legacy database. I've got an active
record class called "School" that uses "set_table_name 'old_school'" to
map to a legacy database table:

class School < ActiveRecord::Base
  set_table_name 'old_school'
end

It works great, until I'm testing and I want to use fixtures. I've got
a fixtures file called "old_school.yml" that doesn't load. Following
some googled advice
(http://www.missiondata.com/blog/uncategorized/80/rails-fixtures-with-models-using-set_table_name/)
I learned that I had to use set_fixture_class to be able to map the
fixture back to the class name:

# in test_helper.rb
class Test::Unit::TestCase
  self.use_transactional_fixtures = true
  self.use_instantiated_fixtures = false

  set_fixture_class :old_school => School

  fixtures :all
end

Seems like it ought to work, but the fixtures still don't load!

Looking in my test.log I find:

Unable to load old_school, underlying cause no such file to load --
old_school

/Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
`require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in
`new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in
`require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:101:in
`require_or_load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:60:in
`depend_on'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:456:in
`require_dependency'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:855:in
`try_to_load_dependency'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:870:in
`require_fixture_classes'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:867:in
`each'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:867:in
`require_fixture_classes'
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:850:in
`fixtures'
./test/test_helper.rb:15
test/functional/admin_controller_test.rb:1:in `require'
test/functional/admin_controller_test.rb:1

If I "require 'school'" by hand, it makes no difference. The fixtures
still don't load.

Has anybody run in to this? Does anyone have any suggestions?

Thanks!

Brent

Use a string, not a class, so 'School', instead of School

Of course!

You know, in hindsight, that seems rather trivially simple. I have no
idea why I didn't try that way back when. Moron award for me. :+)

Thanks! I'm happy to resume full testing now. :slight_smile:

Brent

Tim Connor wrote: