Skip to content

Commit

Permalink
failing test for record not unloaded when a payload is returned
Browse files Browse the repository at this point in the history
It seems common for APIs to return a paylaod when deleting a record.
Although there is a test for when `undefined` is returned from
`deleteRecord` in the adapter here: https://github.com/emberjs/data/blob/master/tests/integration/records/delete-record-test.js#L87

There are currently no tests showing what happens when you return a
payload. It seems like the correct behavior for destroyRecord should be
`deleteRecord` + `save` + `unloadRecord`.
  • Loading branch information
fivetanley committed Jun 27, 2018
1 parent d584076 commit 765fda2
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/integration/records/delete-record-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,77 @@ test('deleting a record that is part of a hasMany removes it from the hasMany re
assert.equal(group.get('people.length'), 1, 'expected 1 related records after delete');
});

test('deleting a record that is part of a hasMany removes it from the hasMany recordArray when adapter deleteRecord function returns a payload', function(assert) {
let group;
let person;
const Group = DS.Model.extend({
people: DS.hasMany('person', { inverse: null, async: false })
});
Group.toString = () => { return 'Group'; }

env.adapter.deleteRecord = function() {
return EmberPromise.resolve({
data: {
id: '1',
type: 'group',
attributes: {}
}
});
};

env.registry.register('model:group', Group);

run(function() {
env.store.push({
data: {
type: 'group',
id: '1',
relationships: {
people: {
data: [
{ type: 'person', id: '1' },
{ type: 'person', id: '2' }
]
}
}
},
included: [
{
type: 'person',
id: '1',
attributes: {
name: 'Adam Sunderland'
}
},
{
type: 'person',
id: '2',
attributes: {
name: 'Dave Sunderland'
}
}
]
});

group = env.store.peekRecord('group', '1');
person = env.store.peekRecord('person', '1');
});

// Sanity Check we are in the correct state.
assert.equal(group.get('people.length'), 2, 'expected 2 related records before delete');
assert.equal(person.get('name'), 'Adam Sunderland', 'expected related records to be loaded');

const promise = run(() => group.destroyRecord());

return promise.then(() => {
// qunit complains if i pass the record to QUnit due to some assertion in ember
// iterating over the properties.
const hasGroup = env.store.peekRecord('group', '1') ? true : false;
assert.equal(hasGroup, false);
assert.equal(person.get('group'), null, 'expected relationship to be null');
});
});

test('records can be deleted during record array enumeration', function(assert) {
var adam, dave;

Expand Down

0 comments on commit 765fda2

Please sign in to comment.