Skip to content

Commit

Permalink
Rejects promise when findQuery doesn't find records
Browse files Browse the repository at this point in the history
  • Loading branch information
kurko committed Jun 27, 2014
1 parent ef83d09 commit 44baf53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions localstorage_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@

if (results.get('length')) {
results = this.loadRelationshipsForMany(type, results);
return Ember.RSVP.resolve(results);
} else {
return Ember.RSVP.reject();
}

return Ember.RSVP.resolve(results);
},

query: function (records, query) {
Expand Down
13 changes: 8 additions & 5 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('find with id', function() {
});
});

test('find non-existing record', function () {
test('#find - rejects promise when non-existing record', function () {
expect(2);

stop();
Expand Down Expand Up @@ -100,10 +100,13 @@ test('findQuery', function() {
equal(get(records, 'length'), 1, 'found results for {b: true}');
start();
});
});

test('#findQuery - rejects promise when there are no records', function() {
stop();
store.findQuery('list', {whatever: "dude"}).then(function(records) {
equal(get(records, 'length'), 0, 'didn\'t find results for nonsense');
store.findQuery('list', {name: /unknown/}).catch(function() {
ok(true);
equal(store.hasRecordForId("list", "unknown"), false);
start();
});
});
Expand Down Expand Up @@ -218,8 +221,8 @@ test('deleteRecord', function() {
expect(2);
stop();
var AssertListIsDeleted = function() {
return store.findQuery('list', { name: 'one' }).then(function(records) {
equal(get(records, 'length'), 0, "No record was found");
return store.findQuery('list', { name: 'one' }).catch(function() {
ok(true, "List was deleted");
start();
});
}
Expand Down

0 comments on commit 44baf53

Please sign in to comment.