Skip to content

Commit

Permalink
Added failing test for #5575
Browse files Browse the repository at this point in the history
  • Loading branch information
jlami authored and broerse committed Sep 3, 2018
1 parent 603884a commit d0cc97a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,64 @@ test("belongsTo relationship with links doesn't trigger extra change notificatio
assert.equal(count, 0);
});

test("async belongsTo returns new object to trigger real change - #5575", function(assert) {
Book.reopen({
author: DS.belongsTo('author', { async: true }),
});
let book, author1, author2;
run(() => {
book = env.store.push({
data: {
id: '1',
type: 'book',
attributes: {
name: "Stanley's Amazing Adventures",
},
},
});
author1 = env.store.push({
data: {
id: '1',
type: 'author',
attributes: {
name: 'Stanley 1',
},
},
});
author2 = env.store.push({
data: {
id: '2',
type: 'author',
attributes: {
name: 'Stanley 2',
},
},
});
});

let lastAuthor;

return run(() => {
lastAuthor = book.get('author');

return lastAuthor.then((cur) => {
assert.ok(cur == null, 'author should start empty');
run(() => { book.set('author', author1) });
assert.ok(book.get('author') !== lastAuthor, "belongsTo promise should be changed");
lastAuthor = book.get('author');
return lastAuthor;
}).then((cur) => {
assert.ok(cur == author1, 'correct author after step 1');
run(() => { book.set('author', author2) });
assert.ok(book.get('author') !== lastAuthor, "belongsTo promise should be changed again");
lastAuthor = book.get('author');
return lastAuthor;
}).then((cur) => {
assert.ok(cur == author2, 'correct author after step 2');
});
});
});

testRecordData(
"belongsTo relationship doesn't trigger when model data doesn't support implicit relationship",
function(assert) {
Expand Down

0 comments on commit d0cc97a

Please sign in to comment.