Skip to content
This repository

fix 'Cannot read property 'map' of undefined' bug in RESTAdapter when API returns an empty array #481

Closed
wants to merge 1 commit into from

3 participants

Vitaly A. Sorokin Peter Wagenet Tom Dale
Vitaly A. Sorokin

No description provided.

Vitaly A. Sorokin

the subject and commit are self-explanatory i guess

Peter Wagenet
Owner

@erundook Can you write a test that fails without this commit?

Tom Dale
Owner

:+1: to merging after we get a failing unit test.

Vitaly A. Sorokin

i have added the unit test

Tom Dale
Owner

The modified code is in DS.Store but the test you've submitted is in the REST adapter tests. Can we have a unit test for just DS.Store?

Peter Wagenet
Owner

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 20, 2012
Vitaly A. Sorokin svasva fix 'Cannot read property 'map' of undefined' bug in RESTAdapter when…
… API returns an empty array

added a unit test
e73ce10
This page is out of date. Refresh to see the latest.
2  packages/ember-data/lib/system/store.js
@@ -1491,7 +1491,7 @@ DS.Store = Ember.Object.extend(DS._Mappable, {
1491 1491 var clientIds = Ember.A([]);
1492 1492
1493 1493 if (dataList === undefined) {
1494   - dataList = ids;
  1494 + dataList = ids || [];
1495 1495 ids = [];
1496 1496
1497 1497 var adapter = this.adapterForType(type);
15 packages/ember-data/tests/unit/rest_adapter_test.js
@@ -275,7 +275,7 @@ test("add/commit/delete/commit a person from a group, group lifecycle", function
275 275 store.load(Group, { id: 1, name: "Whiskey drinkers"});
276 276 store.load(Person, { id: 1, name: "Tom Dale"});
277 277
278   - var
  278 + var
279 279 person = store.find(Person, 1),
280 280 group = store.find(Group, 1);
281 281
@@ -361,6 +361,19 @@ test("finding all people makes a GET to /people", function() {
361 361 equal(person, store.find(Person, 1), "the record is now in the store, and can be looked up by ID without another Ajax request");
362 362 });
363 363
  364 +test("finding all while server returns an empty array does not fail", function() {
  365 + people = store.find(Person);
  366 +
  367 + expectUrl("/people", "the plural of the model name");
  368 + expectType("GET");
  369 +
  370 + ajaxHash.success([]);
  371 +
  372 + person = people;
  373 +
  374 + expectState('loaded');
  375 +});
  376 +
364 377 test("finding all can sideload data", function() {
365 378 var groups = store.find(Group);
366 379

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.