Skip to content

Commit

Permalink
[FEAT] play nice with route rehydration from shoebox
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Apr 22, 2018
1 parent b418981 commit d3eacea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
14 changes: 10 additions & 4 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
62 changes: 35 additions & 27 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<comment:2>' 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: '<comment:2>' 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) {
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ test('it should cache attributes', function(assert) {
});

const store = createStore({
adapter: DS.JSONAPIAdapter.extend({
shouldBackgroundReloadRecord: () => false
}),
post: Post
});

Expand All @@ -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');
Expand Down

0 comments on commit d3eacea

Please sign in to comment.