diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index 749ec20ac47..b083a475993 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -1691,7 +1691,7 @@ Store = Service.extend({ this._backburner.schedule('normalizeRelationships', this, '_setupRelationships', internalModel, data); this.updateId(internalModel, data); } - + assert(`Your ${internalModel.type.modelName} record was saved but it does not have an id. Please make the server provides an id in the createRecord response or you are setting the on the client side before saving the record.`, internalModel.id !== null); //We first make sure the primary data has been updated //TODO try to move notification to the user to the end of the runloop internalModel.adapterDidCommit(data); diff --git a/tests/integration/adapter/rest-adapter-test.js b/tests/integration/adapter/rest-adapter-test.js index d0b1a9ddcf9..d2ab0e33da5 100644 --- a/tests/integration/adapter/rest-adapter-test.js +++ b/tests/integration/adapter/rest-adapter-test.js @@ -328,14 +328,14 @@ test("createRecord - a serializer's primary key and attributes are consulted whe test("createRecord - a serializer's attributes are consulted when building the payload if no id is pre-defined", function(assert) { var post; env.registry.register('serializer:post', DS.RESTSerializer.extend({ - primarykey: '_id_', - attrs: { name: '_name_' } })); - ajaxResponse(); + ajaxResponse({ + post: { '_name_': "The Parley Letter", id: '1' } + }); run(function() { post = store.createRecord('post', { name: "The Parley Letter" }); diff --git a/tests/integration/adapter/store-adapter-test.js b/tests/integration/adapter/store-adapter-test.js index eec8b75b16b..0094d5a7bdd 100644 --- a/tests/integration/adapter/store-adapter-test.js +++ b/tests/integration/adapter/store-adapter-test.js @@ -1057,7 +1057,7 @@ test("createRecord receives a snapshot", function(assert) { var person; run(function() { - person = store.createRecord('person', { name: "Tom Dale" }); + person = store.createRecord('person', { name: "Tom Dale", id: 1 }); person.save(); }); }); diff --git a/tests/integration/client-id-generation-test.js b/tests/integration/client-id-generation-test.js index 72f008b5afa..b98a439db50 100644 --- a/tests/integration/client-id-generation-test.js +++ b/tests/integration/client-id-generation-test.js @@ -86,7 +86,7 @@ test("empty string and undefined ids should coerce to null", function(assert) { env.adapter.createRecord = function(store, type, record) { assert.equal(typeof get(record, 'id'), 'object', 'correct type'); - return Ember.RSVP.resolve(); + return Ember.RSVP.resolve({ id: 1 }); }; run(function() { diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js index 49a46557509..2300815875a 100644 --- a/tests/integration/relationships/has-many-test.js +++ b/tests/integration/relationships/has-many-test.js @@ -342,6 +342,7 @@ test("A hasMany updated link should not remove new children", function(assert) { env.adapter.createRecord = function(store, snapshot, link, relationship) { return Ember.RSVP.resolve({ + id: 1, links: { comments: '/some/link' } @@ -382,6 +383,7 @@ test("A hasMany updated link should not remove new children when the parent reco env.adapter.createRecord = function(store, snapshot, link, relationship) { return Ember.RSVP.resolve({ + id: 1, links: { comments: '/some/link' } @@ -2207,6 +2209,7 @@ test("adding and removing records from hasMany relationship #2666", function(ass }) }); + var commentId = 4; env.registry.register('adapter:comment', DS.RESTAdapter.extend({ deleteRecord(record) { return Ember.RSVP.resolve(); @@ -2215,7 +2218,7 @@ test("adding and removing records from hasMany relationship #2666", function(ass return Ember.RSVP.resolve(); }, createRecord() { - return Ember.RSVP.resolve(); + return Ember.RSVP.resolve({ comments: { id: commentId++ }}); } })); diff --git a/tests/integration/store-test.js b/tests/integration/store-test.js index df4c42e1acc..15adc9a4727 100644 --- a/tests/integration/store-test.js +++ b/tests/integration/store-test.js @@ -867,6 +867,19 @@ testInDebug('store#findRecord that returns an array should assert', assert => { }, /expected the primary data returned from a `findRecord` response to be an object but instead it found an array/); }); +testInDebug('store#didSaveRecord should assert when the response to a save does not include the id', function(assert) { + env.adapter.createRecord = function() { + return {}; + }; + + assert.expectAssertion(function() { + run(function() { + var car = store.createRecord('car'); + car.save(); + }); + }, /record was saved but it does not have an id. Please make the server provides an id in the createRecord/); +}); + module("integration/store - queryRecord", { beforeEach() { initializeStore(DS.Adapter.extend()); @@ -892,3 +905,5 @@ testInDebug('store#queryRecord should assert when normalized payload of adapter }); }, /Expected the primary data returned by the serializer for a `queryRecord` response to be a single object or null but instead it was an array./); }); + + diff --git a/tests/unit/model-test.js b/tests/unit/model-test.js index a58452a6537..ea2cc1dc17a 100644 --- a/tests/unit/model-test.js +++ b/tests/unit/model-test.js @@ -370,7 +370,7 @@ test("changedAttributes() works while the record is being saved", function(asser assert.deepEqual(toObj(cat.changedAttributes()), { name: [undefined, 'Argon'], likes: [undefined, 'Cheese'] }); - return {}; + return { id: 1 }; } }); var Mascot = DS.Model.extend({