I want to stick my models in a module

I’ve got enough models now that I’d like to separate them into
modules. For example, I have the class Player that I want to stick in
the Trainer module. I’ve changed the definition to

class Trainer::Player

I’ve created a models/trainer dir, test/unit/trainer, and
test/fixtures/trainer. Change the PlayerTest class to be
Trainer::PlayerTest. I get the following error when I try to run it:

  1. Error:
    test_validate_range(Trainer::PlayerTest):
    FixtureClassNotFound: The class “Player” was not found.
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/fixtures.rb:403:in
    find' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/fixtures.rb:478:inplayers’
    test/unit/trainer/player_test.rb:48:in `test_validate_range’

I’ve tried creating a model with script/generate model Trainer::Foo
just to see if there was any difference, but it looks like I have it
all right. Do I need to do any special class loading or something?
By the way, I’ve also changed the test helper require to be require
File.dirname(FILE) + ‘/…/…/test_helper’. I really want to group
these into modules, so I’d appreciate any advice.

Pat

On 6/7/06, Pat M. [email protected] wrote:

  1. Error:
    all right. Do I need to do any special class loading or something?
    By the way, I’ve also changed the test helper require to be require
    File.dirname(FILE) + ‘/…/…/test_helper’. I really want to group
    these into modules, so I’d appreciate any advice.

Pat

Also, I can access the model fine with Trainer::Player through
console. So apparently it’s just this fixture loading problem.

On 6/7/06, Pat M. [email protected] wrote:

just to see if there was any difference, but it looks like I have it

Okay so I didn’t actually move the players.yml fixtures file into
the trainer subdir of fixtures. Did that, and now it just says that
it can’t find test/fixtures/players. Well yeah, I don’t want it
to…and the generate script automatically sticks the fixtures in the
trainers subdir.

Hopefully someone knows how to do this. I can’t imagine that Rails
doesn’t let you put your models into modules.

Pat

On 6/7/06, Alex W. [email protected] wrote:

Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Well I just decided to try throwing a string in the fixtures instead
of using the symbol…
fixtures “trainer/player”

That worked for loading the fixtures. Won’t let me use the
players(:first) method of getting something, so I’ve just had to do
Player.find(1). I’m sure there’s a performance hit, but I don’t
really care. I suppose there’s a chance this’ll break in some future
version, but for now it works fine.

Pat

On 6/7/06, Pat M. [email protected] wrote:

trainers subdir.

That worked for loading the fixtures. Won’t let me use the
players(:first) method of getting something, so I’ve just had to do
Player.find(1). I’m sure there’s a performance hit, but I don’t
really care. I suppose there’s a chance this’ll break in some future
version, but for now it works fine.

Pat

Appears to work for some, not for others. Don’t know what the rule
is, and I’m too tired to keep working on this. Still unsolved,
looking for advice.

Pat

Pat M. wrote:

On 6/7/06, Pat M. [email protected] wrote:

just to see if there was any difference, but it looks like I have it

Okay so I didn’t actually move the players.yml fixtures file into
the trainer subdir of fixtures. Did that, and now it just says that
it can’t find test/fixtures/players. Well yeah, I don’t want it
to…and the generate script automatically sticks the fixtures in the
trainers subdir.

Hopefully someone knows how to do this. I can’t imagine that Rails
doesn’t let you put your models into modules.

Pat

I seem to remember seeing a bug about this. Everything works except
fixtures. Can’t seem to find it now, but I think it was on there
somewhere.

I managed to come up with some code that handles this. I know it
would certainly break in some cases, but it works very well for me.
Patch at http://dev.rubyonrails.org/ticket/5332