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’

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
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

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 –

gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:inrequire’
require' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:innew_constants_in’
require' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:101:inrequire_or_load’
depend_on' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:456:inrequire_dependency’
try_to_load_dependency' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:870:inrequire_fixture_classes’
each' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/fixtures.rb:867:inrequire_fixture_classes’
fixtures' ./test/test_helper.rb:15 test/functional/admin_controller_test.rb:1:inrequire’

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?



On Jun 19, 3:52 pm, Brent M. [email protected]

set_fixture_class :old_school => School

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:


Tim C. wrote:

On Jun 19, 3:52�pm, Brent M. [email protected]

� set_fixture_class :old_school => School

Use a string, not a class, so ‘School’, instead of School

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs