From d3eacea34a2b372b8411c652351482649886317d Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Wed, 18 Apr 2018 21:39:36 -0700 Subject: [PATCH] [FEAT] play nice with route rehydration from shoebox --- addon/-private/system/store.js | 14 +++-- .../integration/adapter/rest-adapter-test.js | 62 +++++++++++-------- tests/unit/model-test.js | 5 +- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index 86d9014067c..7f1eff9f1dd 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -793,7 +793,7 @@ Store = Service.extend({ internalModel.loadingData(promise); if (this._pendingFetch.size === 0) { - emberRun.schedule('afterRender', this, this.flushAllPendingFetches); + emberRun.schedule('actions', this, this.flushAllPendingFetches); } this._pendingFetch.get(modelName).push(pendingFetchItem); @@ -872,9 +872,15 @@ Store = Service.extend({ } if (missingInternalModels.length) { - warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + inspect(missingInternalModels.map(r => r.id)), false, { - id: 'ds.store.missing-records-from-adapter' - }); + warn( + 'Ember Data expected to find records with the following ids in the adapter response but they were missing: [ "' + + missingInternalModels.map(r => r.id).join('", "') + + '" ]', + false, + { + id: 'ds.store.missing-records-from-adapter' + } + ); rejectInternalModels(missingInternalModels); } } diff --git a/tests/integration/adapter/rest-adapter-test.js b/tests/integration/adapter/rest-adapter-test.js index cdb94a18b74..61ca6b3f822 100644 --- a/tests/integration/adapter/rest-adapter-test.js +++ b/tests/integration/adapter/rest-adapter-test.js @@ -1918,40 +1918,48 @@ test('findBelongsTo - passes buildURL the requestType', function(assert) { }); testInDebug('coalesceFindRequests assert.warns if the expected records are not returned in the coalesced request', function(assert) { + assert.expect(2); Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); adapter.coalesceFindRequests = true; - ajaxResponse({ comments: [{ id: 1 }] }); - - let wait; - assert.expectWarning(() => { - run(() => { - store.push({ - data: { - type: 'post', - id: '2', - relationships: { - comments: { - data: [ - { type: 'comment', id: '1' }, - { type: 'comment', id: '2' }, - { type: 'comment', id: '3' } - ] - } - } - } - }); + ajaxResponse({ + comments: [ + { id: '1', type: 'comment' } + ] + }); - let post = store.peekRecord('post', 2); - wait = post.get('comments').catch(e => { - assert.equal(e.message, `Expected: '' to be present in the adapter provided payload, but it was not found.`) - }) - }); + let post = run(() => store.push({ + data: { + type: 'post', + id: '2', + relationships: { + comments: { + data: [ + { type: 'comment', id: '1'}, + { type: 'comment', id: '2'}, + { type: 'comment', id: '3'} + ] + } + } + } + })); - return wait; - }, /expected to find records with the following ids in the adapter response but they were missing: \[2,3\]/); + assert.expectWarning( + () => { + return run(() => { + return post.get('comments') + .catch(e => { + assert.equal( + e.message, + `Expected: '' to be present in the adapter provided payload, but it was not found.` + ); + }); + }); + }, + /expected to find records with the following ids in the adapter response but they were missing: \[ "2", "3" \]/ + ); }); test('groupRecordsForFindMany groups records based on their url', function(assert) { diff --git a/tests/unit/model-test.js b/tests/unit/model-test.js index dc6cae9cd41..ca5bce0f05b 100644 --- a/tests/unit/model-test.js +++ b/tests/unit/model-test.js @@ -352,6 +352,9 @@ test('it should cache attributes', function(assert) { }); const store = createStore({ + adapter: DS.JSONAPIAdapter.extend({ + shouldBackgroundReloadRecord: () => false + }), post: Post }); @@ -366,7 +369,7 @@ test('it should cache attributes', function(assert) { } }); - return store.findRecord('post', 1).then(record => { + return store.findRecord('post', '1').then(record => { record.set('updatedAt', date); assert.deepEqual(date, get(record, 'updatedAt'), 'setting a date returns the same date');