Skip to content

Commit

Permalink
tidy up integration/record-array-manager-test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Oct 19, 2016
1 parent 032d165 commit 28b8343
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions tests/integration/record-array-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ import {module, test} from 'qunit';

import DS from 'ember-data';

var store, env;
var run = Ember.run;
let store, env, manager;

var Person = DS.Model.extend({
const { run } = Ember;

const Person = DS.Model.extend({
name: DS.attr('string'),
cars: DS.hasMany('car', { async: false })
});

var Car = DS.Model.extend({
const Car = DS.Model.extend({
make: DS.attr('string'),
model: DS.attr('string'),
person: DS.belongsTo('person', { async: false })
});

var manager;

module("integration/record_array_manager", {
module('integration/record_array_manager', {
beforeEach() {
env = setupStore({
adapter: DS.RESTAdapter.extend()
Expand Down Expand Up @@ -52,11 +51,11 @@ function tap(obj, methodName, callback) {
return summary;
}

test("destroying the store correctly cleans everything up", function(assert) {
var query = { };
var person;
test('destroying the store correctly cleans everything up', function(assert) {
let query = { };
let person;

run(function() {
run(() => {
store.push({
data: {
type: 'car',
Expand All @@ -74,7 +73,7 @@ test("destroying the store correctly cleans everything up", function(assert) {
});
});

run(function() {
run(() => {
store.push({
data: {
type: 'person',
Expand All @@ -94,50 +93,54 @@ test("destroying the store correctly cleans everything up", function(assert) {
person = store.peekRecord('person', 1);
});

var filterd = manager.createFilteredRecordArray(Person, function() { return true; });
var filterd2 = manager.createFilteredRecordArray(Person, function() { return true; });
var all = store.peekAll('person');
var adapterPopulated = manager.createAdapterPopulatedRecordArray(Person, query);
let filterd = manager.createFilteredRecordArray(Person, () => true);
let filterd2 = manager.createFilteredRecordArray(Person, () => true);
let all = store.peekAll('person');
let adapterPopulated = manager.createAdapterPopulatedRecordArray(Person, query);

var filterdSummary = tap(filterd, 'willDestroy');
var filterd2Summary = tap(filterd2, 'willDestroy');
var allSummary = tap(all, 'willDestroy');
var adapterPopulatedSummary = tap(adapterPopulated, 'willDestroy');
let filterdSummary = tap(filterd, 'willDestroy');
let filterd2Summary = tap(filterd2, 'willDestroy');
let allSummary = tap(all, 'willDestroy');
let adapterPopulatedSummary = tap(adapterPopulated, 'willDestroy');

let internalPersonModel = person._internalModel;

assert.equal(filterdSummary.called.length, 0);
assert.equal(filterd2Summary.called.length, 0);
assert.equal(allSummary.called.length, 0);
assert.equal(adapterPopulatedSummary.called.length, 0);

assert.equal(person._internalModel._recordArrays.list.length, 3, 'expected the person to be a member of 3 recordArrays');
assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 3, 'expected the person to be a member of 3 recordArrays');

Ember.run(filterd2, filterd2.destroy);
assert.equal(person._internalModel._recordArrays.list.length, 2, 'expected the person to be a member of 2 recordArrays');

assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 2, 'expected the person to be a member of 2 recordArrays');
assert.equal(filterd2Summary.called.length, 1);

assert.equal(manager.liveRecordArrays.has(all.type), true);

Ember.run(all, all.destroy);
assert.equal(person._internalModel._recordArrays.list.length, 1, 'expected the person to be a member of 1 recordArrays');

assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 1, 'expected the person to be a member of 1 recordArrays');
assert.equal(allSummary.called.length, 1);
assert.equal(manager.liveRecordArrays.has(all.type), false);

Ember.run(manager, manager.destroy);
assert.equal(person._internalModel._recordArrays.list.length, 0, 'expected the person to be a member of no recordArrays');

assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 0, 'expected the person to be a member of no recordArrays');
assert.equal(filterdSummary.called.length, 1);
assert.equal(filterd2Summary.called.length, 1);
assert.equal(allSummary.called.length, 1);
assert.equal(adapterPopulatedSummary.called.length, 1);
});

test("Should not filter a store.peekAll() array when a record property is changed", function(assert) {
var car;

var populateLiveRecordArray = tap(store.recordArrayManager, 'populateLiveRecordArray');
var updateFilterRecordArray = tap(store.recordArrayManager, 'updateFilterRecordArray');
test('Should not filter a store.peekAll() array when a record property is changed', function(assert) {
let populateLiveRecordArray = tap(store.recordArrayManager, 'populateLiveRecordArray');
let updateFilterRecordArray = tap(store.recordArrayManager, 'updateFilterRecordArray');

store.peekAll('car');

run(function() {
let car = run(() => {
store.push({
data: {
type: 'car',
Expand All @@ -153,19 +156,17 @@ test("Should not filter a store.peekAll() array when a record property is change
}
}
});
car = store.peekRecord('car', 1);

return store.peekRecord('car', 1);
});

assert.equal(populateLiveRecordArray.called.length, 1);
assert.equal(updateFilterRecordArray.called.length, 0);

run(function() {
car.set('model', 'Mini');
});
run(() => car.set('model', 'Mini'));

assert.equal(populateLiveRecordArray.called.length, 1);
assert.equal(updateFilterRecordArray.called.length, 0);

});

test('#GH-4041 store#query AdapterPopulatedRecordArrays are removed from their managers instead of retained when #destroy is called', function(assert) {
Expand All @@ -181,13 +182,12 @@ test('#GH-4041 store#query AdapterPopulatedRecordArrays are removed from their m
}
});
});

const query = {};

var adapterPopulated = manager.createAdapterPopulatedRecordArray(Car, query);
let adapterPopulated = manager.createAdapterPopulatedRecordArray(Car, query);

run(() => {
adapterPopulated.destroy();
});
run(() => adapterPopulated.destroy());

assert.equal(manager._adapterPopulatedRecordArrays.length, 0);
});

0 comments on commit 28b8343

Please sign in to comment.