From 60313970d6591be51cd29c6137367721465294fc Mon Sep 17 00:00:00 2001 From: Joe Rossi Date: Mon, 12 May 2014 18:25:09 -0400 Subject: [PATCH 1/4] Reject sooner if no record or the record does not have an ID. --- localstorage_adapter.js | 15 +++++++-------- test/tests.js | 8 ++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/localstorage_adapter.js b/localstorage_adapter.js index 2f73899..7afb0b6 100644 --- a/localstorage_adapter.js +++ b/localstorage_adapter.js @@ -123,20 +123,19 @@ return new Ember.RSVP.Promise(function(resolve, reject) { var record = Ember.A(namespace.records[id]); - if (allowRecursive && record) { + if (!record || !record.hasOwnProperty('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) { diff --git a/test/tests.js b/test/tests.js index 704b8ad..fb620cb 100644 --- a/test/tests.js +++ b/test/tests.js @@ -64,6 +64,14 @@ test('find with id', function() { }); }); +test('find non-existing record', function () { + stop(); + store.find("list", "unknown").catch(function () { + ok(true); + start(); + }); +}); + test('findQuery', function() { stop(); From ef83d09b63cc7912c5609e25dcd96eb9466d5a41 Mon Sep 17 00:00:00 2001 From: Joe Rossi Date: Tue, 3 Jun 2014 21:11:09 -0400 Subject: [PATCH 2/4] Un-index and remove before rejecting. --- localstorage_adapter.js | 1 + test/tests.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/localstorage_adapter.js b/localstorage_adapter.js index 7afb0b6..99d3c0f 100644 --- a/localstorage_adapter.js +++ b/localstorage_adapter.js @@ -124,6 +124,7 @@ var record = Ember.A(namespace.records[id]); if (!record || !record.hasOwnProperty('id')) { + store.dematerializeRecord(store.typeMapFor(type).idToRecord[id]); reject(); return; } diff --git a/test/tests.js b/test/tests.js index fb620cb..644d74f 100644 --- a/test/tests.js +++ b/test/tests.js @@ -65,9 +65,12 @@ test('find with id', function() { }); test('find non-existing record', function () { + expect(2); + stop(); store.find("list", "unknown").catch(function () { ok(true); + equal(store.hasRecordForId("list", "unknown"), false); start(); }); }); From 44baf531f9e3ea614cfe7d46c09289c72c928977 Mon Sep 17 00:00:00 2001 From: Alexandre de Oliveira Date: Fri, 27 Jun 2014 00:20:34 -0300 Subject: [PATCH 3/4] Rejects promise when findQuery doesn't find records --- localstorage_adapter.js | 5 +++-- test/tests.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/localstorage_adapter.js b/localstorage_adapter.js index 99d3c0f..539c9d9 100644 --- a/localstorage_adapter.js +++ b/localstorage_adapter.js @@ -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 644d74f..eb9ae3c 100644 --- a/test/tests.js +++ b/test/tests.js @@ -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(); @@ -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(); }); }); @@ -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(); }); } From 2456d7711cb4cc763222eac0e7f3af45e2bc5917 Mon Sep 17 00:00:00 2001 From: Alexandre de Oliveira Date: Fri, 27 Jun 2014 00:43:13 -0300 Subject: [PATCH 4/4] Bumps up version to 0.3.2 --- CHANGELOG.md | 8 ++++++++ bower.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md 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 "