Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Should destroy all models properly when they are provided with givenModel as an Array. #54

Open
MrCoder opened this issue Jun 15, 2015 · 0 comments

Comments

@MrCoder
Copy link

MrCoder commented Jun 15, 2015

When a model is initialised with an Array, the model instances can be created properly, but an Error will be thrown when the helper tries to destroy them. For example, the following code created to model instances:

helpers.beforeEach.givenModel('xxx-test-model', [{name: 'name0'}, {name: 'name1'}]);

The afterEach method willl fail because the array does not have a destroy method:

this[modelKey].destroy(done);

we should test if it is an array and handle it properly. E.g.

function _destroy(aModel, cb) {
  aModel.destroy(cb);
}

afterEach(function(done) {
  var model = this[modelKey];
  if (Object.prototype.toString.call(model) === '[object Array]') {
    async.each(
      model,
      _destroy.bind(this),
      done);
  } else {
    model.destroy(done);
  }
});
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant