2017-12-15 21:39:18 +00:00
|
|
|
import { getOwner } from '@ember/application';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { moduleForModel } from 'ember-qunit';
|
|
|
|
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
|
|
|
|
|
|
|
|
export default function(modelName, description, options = { needs: [] }) {
|
|
|
|
// moduleForModel correctly wires up #Serializer.store,
|
|
|
|
// but module does not.
|
|
|
|
moduleForModel(modelName, description, {
|
|
|
|
unit: true,
|
|
|
|
needs: options.needs,
|
|
|
|
beforeEach() {
|
|
|
|
const model = this.subject();
|
|
|
|
|
|
|
|
// Initializers don't run automatically in unit tests
|
|
|
|
fragmentSerializerInitializer(getOwner(model));
|
|
|
|
|
|
|
|
// Reassign the subject to provide the serializer
|
|
|
|
this.subject = () => model.store.serializerFor(modelName);
|
|
|
|
|
2018-02-20 20:04:36 +00:00
|
|
|
// Expose the store as well, since it is a parameter for many serializer methods
|
|
|
|
this.store = model.store;
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
if (options.beforeEach) {
|
|
|
|
options.beforeEach.apply(this, arguments);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
afterEach() {
|
|
|
|
if (options.beforeEach) {
|
|
|
|
options.beforeEach.apply(this, arguments);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|