diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..951a8d8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# ember-localstorage-adapter + +## Master + +### 0.3.2 (June 27, 2014) + +* `#find` rejects its promise if no record is found. +* `#findQuery` rejects its promise if no records are found. diff --git a/bower.json b/bower.json index a4c64ef..315db2c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ember-localstorage-adapter", - "version": "0.3.1", + "version": "0.3.2", "homepage": "https://github.com/rpflorence/ember-localstorage-adapter", "authors": [ "Ryan Florence " diff --git a/localstorage_adapter.js b/localstorage_adapter.js index 2f73899..539c9d9 100644 --- a/localstorage_adapter.js +++ b/localstorage_adapter.js @@ -123,20 +123,20 @@ return new Ember.RSVP.Promise(function(resolve, reject) { var record = Ember.A(namespace.records[id]); - if (allowRecursive && record) { + if (!record || !record.hasOwnProperty('id')) { + store.dematerializeRecord(store.typeMapFor(type).idToRecord[id]); + reject(); + return; + } + + if (allowRecursive) { adapter.loadRelationships(type, record).then(function(finalRecord) { resolve(finalRecord); }); } else { - if (!record) { - reject(); - } else { - resolve(record); - } + resolve(record); } }); - - resolve(record); }, findMany: function (store, type, ids) { @@ -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) { diff --git a/test/tests.js b/test/tests.js index 704b8ad..eb9ae3c 100644 --- a/test/tests.js +++ b/test/tests.js @@ -64,6 +64,17 @@ test('find with id', function() { }); }); +test('#find - rejects promise when non-existing record', function () { + expect(2); + + stop(); + store.find("list", "unknown").catch(function () { + ok(true); + equal(store.hasRecordForId("list", "unknown"), false); + start(); + }); +}); + test('findQuery', function() { stop(); @@ -89,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(); }); }); @@ -207,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(); }); }