Resolving a model in a sub directory


#1

My models sub directory is really just a directory of raw Ember objects. For maintainability, we have a number of sub directories, each of which consist of a set of models defined as subclasses of Ember.Object

What works

When developing unit tests for models that exist directly beneath the models folder, then in tests I can create a unit test like so:

moduleFor('model:my-object', 'Unit | Model | my object', {
    unit: true,
});

test('I can access object', function(assert) {
    const o = this.subject();
    assert.ok(o);
});

This works great. I can access an object using this.subject() and everything works as expected.

What doesn’t work

I am having difficulty creating a unit test against any object in a sub directory. E.g Sample directory and sub-directory with goal of testing User object.

 models/
     my-object.js
     users/
         user.js

Writing the following in tests/unit/models/users/user.js

moduleFor('model:user', 'Unit | Model | my object', {
    unit: true,
});

test('I can access user', function(assert) {
    const user = this.subject();
    assert.ok(user);
});

generates an error like this:

 TypeError: Attempting to register an unknown factory: `model:user`

I have tried the changing this line:

moduleFor('model:user', 'Unit | Model | my object', `...

to:

moduleFor('model:users/user', 'Unit | Model | my object', `...

and a few other variants, but it’s clear I don’t know what the resolver expects here to get access to the right object.

Any help would be appreciated!

Scott