Skip to content

Commit

Permalink
store#unloadRecord to destroy record. add test to show record is
Browse files Browse the repository at this point in the history
destroyed and observers removed
  • Loading branch information
ryanpatrickcook committed May 4, 2016
1 parent 2001ee3 commit 9788587
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ Store = Service.extend({
*/
unloadRecord(record) {
record.unloadRecord();
record.destroy();
},

// ................
Expand Down Expand Up @@ -1360,8 +1361,7 @@ Store = Service.extend({

for (let i = 0; i < records.length; i++) {
record = records[i];
record.unloadRecord();
record.destroy(); // maybe within unloadRecord
this.unloadRecord(record);
}

typeMap.metadata = new EmptyObject();
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/store/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,39 @@ test("unload a record", function(assert) {
});
});

test("unload a record - observers should be removed", function(assert) {
assert.expect(3);

run(function() {
store.push({
data: {
type: 'record',
id: '1',
attributes: {
title: 'toto'
}
}
});

store.findRecord('record', 1).then(function(record) {
Ember.addObserver(record, 'title', record, function() {
assert.ok(false, 'observer for record.title');
});

run(function() {
store.unloadRecord(record);
});

run(function() {
let observers = Ember.observersFor(record, 'title');
assert.equal(get(record, 'isDeleted'), true, 'record is deleted');
assert.equal(get(record, 'isDestroyed'), true, 'record is destroyed');
assert.equal(observers.length, 0, 'record should not have observers');
});
});
});
});

module("DS.Store - unload record with relationships");


Expand Down

0 comments on commit 9788587

Please sign in to comment.