Skip to content

Commit 1c210ba

Browse files
author
Stanley Stuart
committed
improve error message for push
fixes warp-drive-dataGH-2201
1 parent 689b2fa commit 1c210ba

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/ember-data/lib/system/store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ Store = Ember.Object.extend({
12931293
// _partial is an internal param used by `update`.
12941294
// If passed, it means that the data should be
12951295
// merged into the existing data, not replace it.
1296-
1297-
Ember.assert("You must include an `id` for " + typeName+ " in a hash passed to `push`", data.id != null);
1296+
Ember.assert("Expected an object as `data` in a call to push for " + typeName + " , but was " + data, Ember.typeOf(data) === 'object');
1297+
Ember.assert("You must include an `id` for " + typeName + " in an object passed to `push`", data.id != null);
12981298

12991299
var type = this.modelFor(typeName);
13001300

packages/ember-data/tests/unit/store/push_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,23 @@ test("Calling pushPayload without a type should use a model's serializer when no
316316

317317
equal(person.get('firstName'), "Yehuda", "you can push raw JSON into the store");
318318
});
319+
320+
test('calling push without data argument as an object raises an error', function(){
321+
var invalidValues = [
322+
undefined,
323+
null,
324+
1,
325+
'string',
326+
Ember.Object.create(),
327+
Ember.Object.extend(),
328+
true
329+
];
330+
331+
expect(invalidValues.length);
332+
333+
Ember.EnumerableUtils.forEach(invalidValues, function(invalidValue){
334+
throws(function(){
335+
store.push('person', invalidValue);
336+
}, /object/);
337+
});
338+
});

0 commit comments

Comments
 (0)