Skip to content

Commit

Permalink
reject with useful reason, rather then undefined when a scheduled fet…
Browse files Browse the repository at this point in the history
…ch fails to contain an expected record.
  • Loading branch information
stefanpenner committed Mar 3, 2017
1 parent 7f590d8 commit 20d4190
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,11 @@ Store = Service.extend({

function rejectInternalModels(internalModels, error) {
for (let i = 0, l = internalModels.length; i < l; i++) {
let pair = seeking[internalModels[i].id];
let internalModel = internalModels[i];
let pair = seeking[internalModel.id];

if (pair) {
pair.resolver.reject(error);
pair.resolver.reject(error || new Error(`Expected: '${internalModel}' to be present in the adapter provided payload, but it was not found.`));
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions tests/unit/store/adapter-interop-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,22 +818,25 @@ test("the promise returned by `_scheduleFetch`, when it rejects, does not depend
}
});

var store = createStore({
adapter: adapter,
let store = createStore({
adapter: Adapter,
test: Person
});

run(function () {
var davidPromise = store.findRecord('test', 'david');
var igorPromise = store.findRecord('test', 'igor');
return run(() => {
let david = store.findRecord('test', 'david');
let igor = store.findRecord('test', 'igor');
let wait = [];

igorPromise.then(null, assert.wait(function () {
assert.equal(davidResolved, false, "Igor did not need to wait for David");
wait.push(igor.catch(() => {
assert.equal(davidResolved, false, 'Igor did not need to wait for David');
}));

davidPromise.then(assert.wait(function () {
assert.equal(davidResolved, true, "David resolved");
wait.push(david.then(() => {
assert.equal(davidResolved, true, 'David resolved');
}));

return Ember.RSVP.Promise.all(wait);
});
});

Expand Down

0 comments on commit 20d4190

Please sign in to comment.