method

set_fixture_class

set_fixture_class(class_names = {})
public

Sets the model class for a fixture when the class name cannot be inferred from the fixture name.

Examples:

set_fixture_class some_fixture:        SomeModel,
                  'namespaced/fixture' => Another::Model

The keys must be the fixture names, that coincide with the short paths to the fixture files.

1Note

Use it to solve FixtureClassNotFound errors.

gdelfino ยท Oct 12, 2009

If you are using a non standard table name by means of +set_table_name+ in your model:

class MyClassName < ActiveRecord::Base
set_table_name "mytablename"
end

then you will get +FixtureClassNotFound+ errors when you try to use fixtures in you unit tests. To solve this use +set_fixture_class+ inside your test:

require 'test_helper'
class MyClassNameTest < ActiveSupport::TestCase
set_fixture_class :mytablename => MyClassName  
end

and rename your fixture file to +mytablename.yml+