From 6210041b1b90862647a6b696077a50f44ddb3db7 Mon Sep 17 00:00:00 2001 From: Christoffer Persson Date: Thu, 25 Jun 2015 00:43:45 +0200 Subject: [PATCH] [CLEANUP beta] Remove Snapshot deprecations --- packages/ember-data/lib/system/snapshot.js | 83 ---------- .../tests/integration/snapshot-test.js | 142 ------------------ 2 files changed, 225 deletions(-) diff --git a/packages/ember-data/lib/system/snapshot.js b/packages/ember-data/lib/system/snapshot.js index 1d1e4a7dbff..1c2667fe03a 100644 --- a/packages/ember-data/lib/system/snapshot.js +++ b/packages/ember-data/lib/system/snapshot.js @@ -28,30 +28,6 @@ export default function Snapshot(internalModel) { this.modelName = internalModel.type.modelName; this._changedAttributes = record.changedAttributes(); - - // The following code is here to keep backwards compatibility when accessing - // `constructor` directly. - // - // With snapshots you should use `type` instead of `constructor`. - // - // Remove for Ember Data 1.0. - var callDeprecate = true; - - Object.defineProperty(this, 'constructor', { - get: function() { - // Ugly hack since accessing error.stack (done in `Ember.deprecate()`) - // causes the internals of Chrome to access the constructor, which then - // causes an infinite loop if accessed and calls `Ember.deprecate()` - // again. - if (callDeprecate) { - callDeprecate = false; - Ember.deprecate('Usage of `snapshot.constructor` is deprecated, use `snapshot.type` instead.'); - callDeprecate = true; - } - - return this.type; - } - }); } Snapshot.prototype = { @@ -359,35 +335,6 @@ Snapshot.prototype = { this.record.eachRelationship(callback, binding); }, - /** - @method get - @param {String} keyName - @return {Object} The property value - @deprecated Use [attr](#method_attr), [belongsTo](#method_belongsTo) or [hasMany](#method_hasMany) instead - */ - get: function(keyName) { - Ember.deprecate('Using DS.Snapshot.get() is deprecated. Use .attr(), .belongsTo() or .hasMany() instead.'); - - if (keyName === 'id') { - return this.id; - } - - if (keyName in this._attributes) { - return this.attr(keyName); - } - - var relationship = this._internalModel._relationships.get(keyName); - - if (relationship && relationship.relationshipMeta.kind === 'belongsTo') { - return this.belongsTo(keyName); - } - if (relationship && relationship.relationshipMeta.kind === 'hasMany') { - return this.hasMany(keyName); - } - - return get(this.record, keyName); - }, - /** @method serialize @param {Object} options @@ -395,37 +342,7 @@ Snapshot.prototype = { */ serialize: function(options) { return this.record.store.serializerFor(this.modelName).serialize(this, options); - }, - - /** - @method unknownProperty - @param {String} keyName - @return {Object} The property value - @deprecated Use [attr](#method_attr), [belongsTo](#method_belongsTo) or [hasMany](#method_hasMany) instead - */ - unknownProperty: function(keyName) { - return this.get(keyName); - }, - - /** - @method _createSnapshot - @private - */ - _createSnapshot: function() { - Ember.deprecate("You called _createSnapshot on what's already a DS.Snapshot. You shouldn't manually create snapshots in your adapter since the store passes snapshots to adapters by default."); - return this; } }; -Object.defineProperty(Snapshot.prototype, 'typeKey', { - enumerable: false, - get: function() { - Ember.deprecate('Snapshot.typeKey is deprecated. Use snapshot.modelName instead.'); - return this.modelName; - }, - set: function() { - Ember.assert('Setting snapshot.typeKey is not supported. In addition, Snapshot.typeKey has been deprecated for Snapshot.modelName.'); - } -}); - export default Snapshot; diff --git a/packages/ember-data/tests/integration/snapshot-test.js b/packages/ember-data/tests/integration/snapshot-test.js index 0f076532c74..cd2da929fec 100644 --- a/packages/ember-data/tests/integration/snapshot-test.js +++ b/packages/ember-data/tests/integration/snapshot-test.js @@ -37,23 +37,6 @@ test("record._createSnapshot() returns a snapshot", function() { }); }); -test("snapshot._createSnapshot() returns a snapshot (self) but is deprecated", function() { - expect(2); - - run(function() { - var post = env.store.push('post', { id: 1, title: 'Hello World' }); - var snapshot1 = post._createSnapshot(); - var snapshot2; - - expectDeprecation(function() { - snapshot2 = snapshot1._createSnapshot(); - }, /You called _createSnapshot on what's already a DS.Snapshot. You shouldn't manually create snapshots in your adapter since the store passes snapshots to adapters by default./); - - ok(snapshot2 === snapshot1, 'snapshot._createSnapshot() returns self'); - }); - -}); - test("snapshot.id, snapshot.type and snapshot.modelName returns correctly", function() { expect(3); @@ -67,27 +50,6 @@ test("snapshot.id, snapshot.type and snapshot.modelName returns correctly", func }); }); -if (Ember.platform.hasPropertyAccessors) { - test("snapshot.constructor is unique and deprecated", function() { - expect(4); - - run(function() { - var comment = env.store.push('comment', { id: 1, body: 'This is comment' }); - var post = env.store.push('post', { id: 2, title: 'Hello World' }); - var commentSnapshot = comment._createSnapshot(); - var postSnapshot = post._createSnapshot(); - - expectDeprecation(function() { - equal(commentSnapshot.constructor.modelName, 'comment', 'constructor.modelName is unique per type'); - }); - - expectDeprecation(function() { - equal(postSnapshot.constructor.modelName, 'post', 'constructor.modelName is unique per type'); - }); - }); - }); -} - test("snapshot.attr() does not change when record changes", function() { expect(2); @@ -551,94 +513,6 @@ test("snapshot.hasMany() does not trigger a call to store.scheduleFetch", functi }); }); -test("snapshot.get() is deprecated", function() { - expect(1); - - run(function() { - var post = env.store.push('post', { id: 1, title: 'Hello World' }); - var snapshot = post._createSnapshot(); - - expectDeprecation(function() { - snapshot.get('title'); - }, 'Using DS.Snapshot.get() is deprecated. Use .attr(), .belongsTo() or .hasMany() instead.'); - }); -}); - -test("snapshot.get() returns id", function() { - expect(2); - - run(function() { - var post = env.store.push('post', { id: 1, title: 'Hello World' }); - var snapshot = post._createSnapshot(); - - expectDeprecation(function() { - equal(snapshot.get('id'), '1', 'snapshot id is correct'); - }); - }); -}); - -test("snapshot.get() returns attribute", function() { - expect(2); - - run(function() { - var post = env.store.push('post', { id: 1, title: 'Hello World' }); - var snapshot = post._createSnapshot(); - - expectDeprecation(function() { - equal(snapshot.get('title'), 'Hello World', 'snapshot title is correct'); - }); - }); -}); - -test("snapshot.get() returns belongsTo", function() { - expect(3); - - run(function() { - var comment = env.store.push('comment', { id: 1, body: 'This is a comment', post: 2 }); - var snapshot = comment._createSnapshot(); - var relationship; - - expectDeprecation(function() { - relationship = snapshot.get('post'); - }); - - ok(relationship instanceof DS.Snapshot, 'relationship is an instance of DS.Snapshot'); - equal(relationship.id, '2', 'relationship id is correct'); - }); -}); - -test("snapshot.get() returns hasMany", function() { - expect(3); - - run(function() { - var post = env.store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] }); - var snapshot = post._createSnapshot(); - var relationship; - - expectDeprecation(function() { - relationship = snapshot.get('comments'); - }); - - ok(relationship instanceof Array, 'relationship is an instance of Array'); - equal(relationship.length, 2, 'relationship has two items'); - }); -}); - -test("snapshot.get() proxies property to record unless identified as id, attribute or relationship", function() { - expect(2); - - run(function() { - var post = env.store.push('post', { id: 1, title: 'Hello World' }); - var snapshot = post._createSnapshot(); - - post.set('category', 'Ember.js'); // category is not defined as an DS.attr() - - expectDeprecation(function() { - equal(snapshot.get('category'), 'Ember.js', 'snapshot proxies unknown property correctly'); - }); - }); -}); - test("snapshot.serialize() serializes itself", function() { expect(2); @@ -652,19 +526,3 @@ test("snapshot.serialize() serializes itself", function() { deepEqual(snapshot.serialize({ includeId: true }), { id: "1", author: undefined, title: 'Hello World' }, 'serialize takes options'); }); }); - -if (Ember.platform.hasPropertyAccessors) { - test('snapshot.typeKey is deprecated', function() { - expect(1); - - run(function() { - var post = env.store.push('post', { id: 1, title: 'Hello World' }); - var snapshot = post._createSnapshot(); - - expectDeprecation(function() { - return snapshot.typeKey; - }); - }); - - }); -}