Skip to content

Commit

Permalink
Add test for removing and unloading a record from a hasMany relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
sudowork committed Jun 20, 2017
1 parent ac01921 commit fb5f6bf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/integration/relationships/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,37 @@ testInDebug('A sync hasMany errors out if there are unlaoded records in it', fun
}, /You looked up the 'comments' relationship on a 'post' with id 1 but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async \('DS.hasMany\({ async: true }\)'\)/);
});

testInDebug('After removing and unloading a record, a hasMany relationship should still be valid', function(assert) {
const post = run(() => {
env.store.push({
data: {
type: 'post',
id: '1',
relationships: {
comments: {
data: [
{ type: 'comment', id: '1' }
]
}
}
},
included: [
{ type: 'comment', id: '1' }
]
});
const post = env.store.peekRecord('post', 1);
const comments = post.get('comments');
const comment = comments.objectAt(0);
comments.removeObject(comment);
env.store.unloadRecord(comment);
assert.equal(comments.get('length'), 0);
return post;
});

// Explicitly re-get comments
assert.equal(run(post, 'get', 'comments.length'), 0);
});

test("If reordered hasMany data has been pushed to the store, the many array reflects the ordering change - sync", function(assert) {
var comment1, comment2, comment3, comment4;
var post;
Expand Down

0 comments on commit fb5f6bf

Please sign in to comment.