From d0cc97a3b5e97faf2d8c6f31c785b2eb68882526 Mon Sep 17 00:00:00 2001 From: Joren l'Ami Date: Wed, 22 Aug 2018 12:25:42 +0200 Subject: [PATCH] Added failing test for #5575 --- .../relationships/belongs-to-test.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js index 47459fdc..b8e99299 100644 --- a/tests/integration/relationships/belongs-to-test.js +++ b/tests/integration/relationships/belongs-to-test.js @@ -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) {