Skip to content

Commit

Permalink
add test and fix for emberjs#5350
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Mar 17, 2018
1 parent 5cf7d25 commit 55fd924
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 2 deletions.
4 changes: 3 additions & 1 deletion addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export default class InternalModel {
// models to rematerialize their records.

return this._isDematerializing ||
this.hasScheduledDestroy() ||
this.isDestroyed ||
this.currentState.stateName === 'root.deleted.saved' ||
this.isEmpty();
Expand Down Expand Up @@ -381,9 +382,10 @@ export default class InternalModel {
this._isDematerializing = true;
this._record.destroy();
this.destroyRelationships();
this.updateRecordArrays();
this.resetRecord();
}

this.updateRecordArrays();
}

deleteRecord() {
Expand Down
116 changes: 115 additions & 1 deletion tests/integration/record-arrays/peeked-records-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Person = DS.Model.extend({
}
});

module('integration/unload-peeked-records', {
module('integration/peeked-records', {
beforeEach() {
store = createStore({
person: Person
Expand Down Expand Up @@ -262,3 +262,117 @@ test('unloadAll followed by peekAll in the same run-loop works as expected', fun
'RecordArray state has not changed any further'
);
});

test('push+materialize => unloadAll => push+materialize works as expected', function(assert) {
function push() {
run(() => {
store.push({
data: [
{
type: 'person',
id: '1',
attributes: {
name: 'John'
}
},
{
type: 'person',
id: '2',
attributes: {
name: 'Joe'
}
}
]
});
});
}
function unload() {
run(() => store.unloadAll('person'));
}
function peek() {
return run(() => store.peekAll('person'));
}

let peekedRecordArray = peek();
let watcher = watchProperties(peekedRecordArray, ['length', '[]']);

push();
assert.watchedPropertyCounts(
watcher,
{ length: 1, '[]': 1 },
'RecordArray state after a single push with multiple records to add'
);

unload();
assert.equal(get(peekedRecordArray, 'length'), 0, 'We no longer have any array content');
assert.watchedPropertyCounts(
watcher,
{ length: 2, '[]': 2 },
'RecordArray state has signaled the unload'
);

push();
assert.equal(get(peekedRecordArray, 'length'), 2, 'We have array content');
assert.watchedPropertyCounts(
watcher,
{ length: 3, '[]': 3 },
'RecordArray state now has records again'
);
});

test('push-without-materialize => unloadAll => push-without-materialize works as expected', function(assert) {
function _push() {
run(() => {
store._push({
data: [
{
type: 'person',
id: '1',
attributes: {
name: 'John'
}
},
{
type: 'person',
id: '2',
attributes: {
name: 'Joe'
}
}
]
});
});
}
function unload() {
run(() => store.unloadAll('person'));
}
function peek() {
return run(() => store.peekAll('person'));
}

let peekedRecordArray = peek();
let watcher = watchProperties(peekedRecordArray, ['length', '[]']);

_push();
assert.watchedPropertyCounts(
watcher,
{ length: 1, '[]': 1 },
'RecordArray state after a single push with multiple records to add'
);

unload();
assert.equal(get(peekedRecordArray, 'length'), 0, 'We no longer have any array content');
assert.watchedPropertyCounts(
watcher,
{ length: 2, '[]': 2 },
'RecordArray state has signaled the unload'
);

_push();
assert.equal(get(peekedRecordArray, 'length'), 2, 'We have array content');
assert.watchedPropertyCounts(
watcher,
{ length: 3, '[]': 3 },
'RecordArray state now has records again'
);
});

0 comments on commit 55fd924

Please sign in to comment.