diff --git a/localstorage_adapter.js b/localstorage_adapter.js index 8ece9df..61a689b 100644 --- a/localstorage_adapter.js +++ b/localstorage_adapter.js @@ -84,12 +84,9 @@ * @param {Array} payload returned JSONs */ extractArray: function(store, type, payload) { - var serializer = this; - - return payload.map(function(record) { - var extracted = serializer.extractSingle(store, type, record); - return serializer.normalize(type, record); - }); + return payload.map(function(json) { + return this.extractSingle(store, type, json); + }, this); } }); diff --git a/test/tests.js b/test/tests.js index 1e7cdcc..ef3b2d8 100644 --- a/test/tests.js +++ b/test/tests.js @@ -378,6 +378,28 @@ test('saves hasMany', function() { }); }); +test("extractArray calls extractSingle", function() { + var callback = sinon.stub(); + + store.get('container').register('serializer:list', DS.LSSerializer.extend({ + extractSingle: function(store, type, payload) { + callback(); + return this.normalize(type, payload); + } + })); + + expect(1); + stop(); + + store.find('list').then(function(lists) { + equal(callback.callCount, 3); + + start(); + }); + + store.get('container').unregister('serializer:list') +}); + // This crashes chrome. // TODO: Figure out a way to test this without using so much memory. //