Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

@svasva

No description provided.

@svasva

the subject and commit are self-explanatory i guess

@wagenet
Owner

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

@tomdale
Owner

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

@svasva

i have added the unit test

@tomdale
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?

@wagenet
Owner

Closing due to inactivity.

@wagenet wagenet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 20, 2012
  1. @svasva

    fix 'Cannot read property 'map' of undefined' bug in RESTAdapter when…

    svasva authored
    … API returns an empty array
    
    added a unit test
This page is out of date. Refresh to see the latest.
View
2  packages/ember-data/lib/system/store.js
@@ -1491,7 +1491,7 @@ DS.Store = Ember.Object.extend(DS._Mappable, {
var clientIds = Ember.A([]);
if (dataList === undefined) {
- dataList = ids;
+ dataList = ids || [];
ids = [];
var adapter = this.adapterForType(type);
View
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
store.load(Group, { id: 1, name: "Whiskey drinkers"});
store.load(Person, { id: 1, name: "Tom Dale"});
- var
+ var
person = store.find(Person, 1),
group = store.find(Group, 1);
@@ -361,6 +361,19 @@ test("finding all people makes a GET to /people", function() {
equal(person, store.find(Person, 1), "the record is now in the store, and can be looked up by ID without another Ajax request");
});
+test("finding all while server returns an empty array does not fail", function() {
+ people = store.find(Person);
+
+ expectUrl("/people", "the plural of the model name");
+ expectType("GET");
+
+ ajaxHash.success([]);
+
+ person = people;
+
+ expectState('loaded');
+});
+
test("finding all can sideload data", function() {
var groups = store.find(Group);
Something went wrong with that request. Please try again.