From 310082b1cf40959be942e95338e95258f0dc9670 Mon Sep 17 00:00:00 2001 From: Stanley Stuart Date: Sat, 6 Jun 2015 16:14:18 -0500 Subject: [PATCH 1/7] Raise errors on deprecation This raises an error when unhandled deprecation warnings exist. By this we enforce that deprecation warnings are properly tested. --- tests/ember-configuration.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ember-configuration.js b/tests/ember-configuration.js index da6f579c218..ad317c1bcdf 100644 --- a/tests/ember-configuration.js +++ b/tests/ember-configuration.js @@ -15,6 +15,7 @@ // Handle testing feature flags ENV['ENABLE_OPTIONAL_FEATURES'] = !!QUnit.urlParams.enableoptionalfeatures; + ENV['RAISE_ON_DEPRECATION'] = true; window.async = function(callback, timeout) { var timer; From 79d04421c82755f819b199c420af28fba8c9c043 Mon Sep 17 00:00:00 2001 From: pangratz Date: Sun, 14 Jun 2015 14:18:47 +0200 Subject: [PATCH 2/7] Expect deprecation warning when payload to store#push contains records --- .../ember-data/tests/unit/store/push-test.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/ember-data/tests/unit/store/push-test.js b/packages/ember-data/tests/unit/store/push-test.js index bd10b941a5b..e3f054d4c30 100644 --- a/packages/ember-data/tests/unit/store/push-test.js +++ b/packages/ember-data/tests/unit/store/push-test.js @@ -184,7 +184,7 @@ test("Calling push on normalize allows partial updates with raw JSON", function equal(person.get('lastName'), "Jackson", "existing fields are untouched"); }); -test("Calling push with a normalized hash containing related records returns a record", function() { +test("DEPRECATED - Calling push with a normalized hash containing related records returns a record", function() { var number1, number2, person; run(function() { number1 = store.push('phone-number', { @@ -198,16 +198,19 @@ test("Calling push with a normalized hash containing related records returns a r number: '5552121', person: 'wat' }); + }); - person = store.push('person', { - id: 'wat', - firstName: 'John', - lastName: 'Smith', - phoneNumbers: [number1, number2] + run(function() { + expectDeprecation(function() { + person = store.push('person', { + id: 'wat', + firstName: 'John', + lastName: 'Smith', + phoneNumbers: [number1, number2] + }); }); }); - deepEqual(person.get('phoneNumbers').toArray(), [number1, number2], "phoneNumbers array is correct"); }); From fe371ef7a57a2011d800d75fe9774bde65e1fed2 Mon Sep 17 00:00:00 2001 From: pangratz Date: Sun, 14 Jun 2015 14:23:32 +0200 Subject: [PATCH 3/7] Soft deprecate `store.pushMany` --- packages/ember-data/lib/system/store.js | 5 ++++- tests/ember-data-setup.js | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index afa41c6cef2..552ef1e9706 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -1888,7 +1888,10 @@ Store = Service.extend({ */ pushMany: function(modelName, datas) { Ember.assert(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelName === 'string'); - Ember.deprecate('Using store.pushMany() has been deprecated since store.push() now handles multiple items. You should use store.push() instead.'); + Ember.deprecate('Using store.pushMany() has been deprecated since store.push() now handles multiple items. You should use store.push() instead.', false, { + id: "ember-data-pushMany" + }); + var length = datas.length; var result = new Array(length); diff --git a/tests/ember-data-setup.js b/tests/ember-data-setup.js index bbe39109a2c..30faf45b04f 100644 --- a/tests/ember-data-setup.js +++ b/tests/ember-data-setup.js @@ -1,5 +1,11 @@ ;(function() { + // Since store.pushMany is used pretty heavily inside the tests, fixing all + // the deprecation warnings at once would be a big changeset. That's why the + // log level for this deprecation is set to LOG, so the deprecations are + // logged but they do not result in a failed test. + Ember.Debug._addDeprecationLevel("ember-data-pushMany", Ember.Debug._deprecationLevels.LOG); + Ember.RSVP.configure('onerror', function(reason) { // only print error messages if they're exceptions; // otherwise, let a future turn of the event loop From 7dc2055b1a19d6beda87332bde87ca36070d6c93 Mon Sep 17 00:00:00 2001 From: pangratz Date: Mon, 22 Jun 2015 23:27:56 +0200 Subject: [PATCH 4/7] Soft deprecate shouldReloadAll and shouldBackgroundReloadRecord --- packages/ember-data/lib/system/adapter.js | 8 ++++++-- tests/ember-data-setup.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/ember-data/lib/system/adapter.js b/packages/ember-data/lib/system/adapter.js index ee66cdd9806..5ada59fe2df 100644 --- a/packages/ember-data/lib/system/adapter.js +++ b/packages/ember-data/lib/system/adapter.js @@ -483,7 +483,9 @@ var Adapter = Ember.Object.extend({ */ shouldReloadAll: function(store, snapshotRecordArray) { var modelName = snapshotRecordArray.type.modelName; - Ember.deprecate(`The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one "${modelName}" record in the store. If you would like to preserve the current behavior please override shouldReloadAll in your adapter:application and return true.`); + Ember.deprecate(`The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one "${modelName}" record in the store. If you would like to preserve the current behavior please override shouldReloadAll in your adapter:application and return true.`, false, { + id: 'ember-data-shouldReloadAll' + }); return true; }, @@ -504,7 +506,9 @@ var Adapter = Ember.Object.extend({ @return {Boolean} */ shouldBackgroundReloadRecord: function(store, snapshot) { - Ember.deprecate('The default behavior of `shouldBackgroundReloadRecord` will change in Ember Data 2.0 to always return true. If you would like to preserve the current behavior please override `shouldBackgroundReloadRecord` in your adapter:application and return false.'); + Ember.deprecate('The default behavior of `shouldBackgroundReloadRecord` will change in Ember Data 2.0 to always return true. If you would like to preserve the current behavior please override `shouldBackgroundReloadRecord` in your adapter:application and return false.', false, { + id: 'ember-data-shouldBackgroundReloadRecord' + }); return false; }, diff --git a/tests/ember-data-setup.js b/tests/ember-data-setup.js index 30faf45b04f..fc8b16f6f41 100644 --- a/tests/ember-data-setup.js +++ b/tests/ember-data-setup.js @@ -6,6 +6,9 @@ // logged but they do not result in a failed test. Ember.Debug._addDeprecationLevel("ember-data-pushMany", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-shouldBackgroundReloadRecord", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-shouldReloadAll", Ember.Debug._deprecationLevels.LOG); + Ember.RSVP.configure('onerror', function(reason) { // only print error messages if they're exceptions; // otherwise, let a future turn of the event loop From db6dfe5fa1f42f469e154e98044d49bf2fd2860b Mon Sep 17 00:00:00 2001 From: pangratz Date: Mon, 22 Jun 2015 23:28:39 +0200 Subject: [PATCH 5/7] Soft deprecate InvalidError expecting JSON-API errors --- packages/ember-data/lib/adapters/errors.js | 4 +++- tests/ember-data-setup.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/ember-data/lib/adapters/errors.js b/packages/ember-data/lib/adapters/errors.js index b4ca080242d..5a1c286429e 100644 --- a/packages/ember-data/lib/adapters/errors.js +++ b/packages/ember-data/lib/adapters/errors.js @@ -79,7 +79,9 @@ AdapterError.prototype = Object.create(EmberError.prototype); */ export function InvalidError(errors) { if (!Ember.isArray(errors)) { - Ember.deprecate('`InvalidError` expects json-api formatted errors.'); + Ember.deprecate('`InvalidError` expects json-api formatted errors.', false, { + id: 'ember-data-invalidError-expects-json-api-errors' + }); errors = errorsHashToArray(errors); } AdapterError.call(this, errors, 'The adapter rejected the commit because it was invalid'); diff --git a/tests/ember-data-setup.js b/tests/ember-data-setup.js index fc8b16f6f41..55717ad4480 100644 --- a/tests/ember-data-setup.js +++ b/tests/ember-data-setup.js @@ -9,6 +9,8 @@ Ember.Debug._addDeprecationLevel("ember-data-shouldBackgroundReloadRecord", Ember.Debug._deprecationLevels.LOG); Ember.Debug._addDeprecationLevel("ember-data-shouldReloadAll", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-invalidError-expects-json-api-errors", Ember.Debug._deprecationLevels.LOG); + Ember.RSVP.configure('onerror', function(reason) { // only print error messages if they're exceptions; // otherwise, let a future turn of the event loop From 21a5a32948b8508fa80a914103523c77709bff58 Mon Sep 17 00:00:00 2001 From: pangratz Date: Mon, 22 Jun 2015 23:29:22 +0200 Subject: [PATCH 6/7] Soft deprecate store#metadataFor/setMetadataFor --- packages/ember-data/lib/system/store.js | 8 ++++++-- tests/ember-data-setup.js | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index 552ef1e9706..fa8568dc250 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -1284,7 +1284,9 @@ Store = Service.extend({ @deprecated */ metadataFor: function(modelName) { - Ember.deprecate("`store.metadataFor()` has been deprecated. You can use `.get('meta')` on relationships and arrays returned from `store.query()`."); + Ember.deprecate("`store.metadataFor()` has been deprecated. You can use `.get('meta')` on relationships and arrays returned from `store.query()`.", false, { + id: 'ember-data-metadataFor' + }); return this._metadataFor(modelName); }, @@ -1310,7 +1312,9 @@ Store = Service.extend({ @deprecated */ setMetadataFor: function(modelName, metadata) { - Ember.deprecate("`store.setMetadataFor()` has been deprecated. Please return meta from your serializer's `extractMeta` hook."); + Ember.deprecate("`store.setMetadataFor()` has been deprecated. Please return meta from your serializer's `extractMeta` hook.", false, { + id: 'ember-data-setMetadataFor' + }); this._setMetadataFor(modelName, metadata); }, diff --git a/tests/ember-data-setup.js b/tests/ember-data-setup.js index 55717ad4480..df4fca7331b 100644 --- a/tests/ember-data-setup.js +++ b/tests/ember-data-setup.js @@ -9,6 +9,9 @@ Ember.Debug._addDeprecationLevel("ember-data-shouldBackgroundReloadRecord", Ember.Debug._deprecationLevels.LOG); Ember.Debug._addDeprecationLevel("ember-data-shouldReloadAll", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-metadataFor", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-setMetadataFor", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-invalidError-expects-json-api-errors", Ember.Debug._deprecationLevels.LOG); Ember.RSVP.configure('onerror', function(reason) { From a044baeb07eeb4f81242c8ceef2e38969e5dc5a4 Mon Sep 17 00:00:00 2001 From: pangratz Date: Mon, 22 Jun 2015 23:29:48 +0200 Subject: [PATCH 7/7] Soft deprecate store.push(type, data) This is used extensively throughout the tests. --- packages/ember-data/lib/system/store.js | 4 +++- tests/ember-data-setup.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index fa8568dc250..beb6247340a 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -1694,7 +1694,9 @@ Store = Service.extend({ if (Ember.typeOf(modelNameArg) === 'object' && Ember.typeOf(dataArg) === 'undefined') { data = modelNameArg; } else { - Ember.deprecate('store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.'); + Ember.deprecate('store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.', false, { + id: 'ember-data-store#push(type, data)' + }); Ember.assert("Expected an object as `data` in a call to `push` for " + modelNameArg + " , but was " + Ember.typeOf(dataArg), Ember.typeOf(dataArg) === 'object'); Ember.assert("You must include an `id` for " + modelNameArg + " in an object passed to `push`", dataArg.id != null && dataArg.id !== ''); data = _normalizeSerializerPayload(this.modelFor(modelNameArg), dataArg); diff --git a/tests/ember-data-setup.js b/tests/ember-data-setup.js index df4fca7331b..ecabe34bddc 100644 --- a/tests/ember-data-setup.js +++ b/tests/ember-data-setup.js @@ -6,6 +6,8 @@ // logged but they do not result in a failed test. Ember.Debug._addDeprecationLevel("ember-data-pushMany", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-store#push(type, data)", Ember.Debug._deprecationLevels.LOG); + Ember.Debug._addDeprecationLevel("ember-data-shouldBackgroundReloadRecord", Ember.Debug._deprecationLevels.LOG); Ember.Debug._addDeprecationLevel("ember-data-shouldReloadAll", Ember.Debug._deprecationLevels.LOG);