54

As far as I can see, when testing ember-data models in ember CLI, all relationships have to be listed in needs. This is fine if the structure is simple, but in many cases there will be multiple layers.

For example, if models are set up with the following relationships defined:

Model a:
   belongsTo: b
   belongsTo: c

Model b:
   hasMany: a
   hasMany: d

Model c:
   hasMany: a
   belongsTo: e

Model d:
   hasMany b

Model e:
   hasMany c

Then every unit test for any of these models will require every other model listed in needs, e.g. A test for c:

needs: [
    'model:a' // Because c -> a
    'model:e' // Because c -> e
    'model:b' // Because c -> a -> b
    'model:d' // Because c -> a -> b -> d
]

My actual configuration is a lot more complicated with 14 models, and each one indirectly related to all the others.

Is my understanding correct? Is there a more efficient way of doing this? Or is there a good reason for doing it this way that I am missing?

aquavitae
  • 17,414
  • 11
  • 63
  • 106
  • I just upgraded a project last night to 0.0.46 and noticed this behavior as well, and I don't recall it happening in prior versions. Could be something new in ember data? – Dhaulagiri Oct 01 '14 at 14:20
  • 6
    The issue is being addressed by [this PR](https://github.com/stefanpenner/ember-cli/pull/2351). – Eduardo M - bbaaxx Nov 14 '14 at 07:52

1 Answers1

1

If you are using Ember default 'Ember-QUnit' then you have to list all the models in needs.

But there is an alternative for testing which I am using i.e. ember-data-factory-guy. This is used to create factory instead of fixture data when testing Model, component, controller etc.

You can go through it.

https://github.com/danielspaniel/ember-data-factory-guy