From 5cef8a13ebdbf14d77f61f4948d40e5a17958885 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Mon, 31 Jul 2017 15:42:46 +0100 Subject: [PATCH] Update imports with codemod --- addon/-private/adapters/build-url-mixin.js | 9 +- addon/-private/adapters/errors.js | 12 +- addon/-private/system/debug/debug-adapter.js | 23 +-- addon/-private/system/is-array-like.js | 7 +- addon/-private/system/many-array.js | 12 +- addon/-private/system/model/errors.js | 28 ++-- addon/-private/system/model/internal-model.js | 36 ++--- addon/-private/system/model/model.js | 41 ++--- addon/-private/system/normalize-model-name.js | 4 +- addon/-private/system/ordered-set.js | 2 +- addon/-private/system/promise-proxies.js | 12 +- addon/-private/system/record-array-manager.js | 19 +-- .../adapter-populated-record-array.js | 14 +- .../record-arrays/filtered-record-array.js | 13 +- .../system/record-arrays/record-array.js | 10 +- .../-private/system/references/belongs-to.js | 4 +- addon/-private/system/references/has-many.js | 11 +- addon/-private/system/references/record.js | 4 +- addon/-private/system/relationship-meta.js | 2 +- .../system/relationships/belongs-to.js | 8 +- addon/-private/system/relationships/ext.js | 15 +- .../-private/system/relationships/has-many.js | 16 +- .../relationship-payloads-manager.js | 4 +- .../system/relationships/state/belongs-to.js | 10 +- .../system/relationships/state/create.js | 4 +- .../relationships/state/relationship.js | 5 +- addon/-private/system/snapshot.js | 18 +-- addon/-private/system/store.js | 33 ++-- addon/-private/system/store/common.js | 6 +- .../system/store/container-instance-cache.js | 3 +- addon/-private/system/store/finders.js | 7 +- .../system/store/serializer-response.js | 4 +- addon/-private/utils.js | 9 +- addon/adapter.js | 4 +- addon/adapters/json-api.js | 8 +- addon/adapters/rest.js | 23 ++- addon/attr.js | 4 +- addon/index.js | 3 +- addon/serializer.js | 4 +- addon/serializers/embedded-records-mixin.js | 17 +- addon/serializers/json-api.js | 14 +- addon/serializers/json.js | 18 +-- addon/serializers/rest.js | 22 ++- addon/transforms/boolean.js | 4 +- addon/transforms/number.js | 4 +- addon/transforms/string.js | 4 +- addon/transforms/transform.js | 4 +- package.json | 2 +- tests/dummy/app/app.js | 3 +- tests/dummy/app/router.js | 4 +- tests/dummy/app/routes/application/route.js | 4 +- tests/dummy/app/routes/index/route.js | 4 +- tests/dummy/app/routes/query/controller.js | 6 +- tests/dummy/app/routes/query/route.js | 6 +- tests/helpers/async.js | 11 +- tests/helpers/custom-adapter.js | 4 +- tests/helpers/destroy-app.js | 4 +- tests/helpers/module-for-acceptance.js | 4 +- tests/helpers/owner.js | 5 +- tests/helpers/start-app.js | 9 +- tests/helpers/store.js | 3 +- .../adapter/build-url-mixin-test.js | 15 +- tests/integration/adapter/find-all-test.js | 18 +-- tests/integration/adapter/find-test.js | 13 +- .../adapter/json-api-adapter-test.js | 11 +- tests/integration/adapter/queries-test.js | 18 +-- .../adapter/record-persistence-test.js | 29 ++-- .../integration/adapter/rest-adapter-test.js | 81 +++++----- tests/integration/adapter/serialize-test.js | 6 +- .../integration/adapter/store-adapter-test.js | 147 +++++++++--------- tests/integration/application-test.js | 13 +- .../non-dasherized-lookups-test.js | 8 +- .../integration/client-id-generation-test.js | 13 +- tests/integration/debug-adapter-test.js | 22 +-- tests/integration/filter-test.js | 16 +- tests/integration/injection-test.js | 14 +- tests/integration/inverse-test.js | 5 +- tests/integration/lifecycle-hooks-test.js | 9 +- tests/integration/multiple-stores-test.js | 3 +- tests/integration/peek-all-test.js | 13 +- .../polymorphic-belongs-to-test.js | 5 +- .../integration/record-array-manager-test.js | 14 +- tests/integration/record-array-test.js | 16 +- .../adapter-populated-record-array-test.js | 8 +- .../records/collection-save-test.js | 21 ++- .../integration/records/delete-record-test.js | 32 ++-- tests/integration/records/error-test.js | 15 +- tests/integration/records/load-test.js | 8 +- .../records/property-changes-test.js | 10 +- .../records/relationship-changes-test.js | 8 +- tests/integration/records/reload-test.js | 20 +-- .../integration/records/rematerialize-test.js | 8 +- tests/integration/records/save-test.js | 22 +-- tests/integration/records/unload-test.js | 24 +-- .../integration/references/belongs-to-test.js | 18 +-- tests/integration/references/has-many-test.js | 22 +-- tests/integration/references/record-test.js | 16 +- .../relationships/belongs-to-test.js | 42 ++--- .../relationships/has-many-test.js | 130 +++++++++------- .../inverse-relationships-test.js | 7 +- .../relationships/many-to-many-test.js | 14 +- .../relationships/one-to-many-test.js | 10 +- .../relationships/one-to-one-test.js | 14 +- .../polymorphic-mixins-belongs-to-test.js | 7 +- .../polymorphic-mixins-has-many-test.js | 7 +- .../embedded-records-mixin-test.js | 10 +- .../serializers/json-api-serializer-test.js | 8 +- .../serializers/json-serializer-test.js | 8 +- .../serializers/rest-serializer-test.js | 17 +- tests/integration/setup-container-test.js | 9 +- tests/integration/snapshot-test.js | 10 +- tests/integration/store-test.js | 25 +-- .../store/json-api-validation-test.js | 14 +- tests/integration/store/query-record-test.js | 12 +- tests/test-helper.js | 9 +- tests/unit/adapter-errors-test.js | 6 +- .../build-url-mixin/path-for-type-test.js | 5 +- .../adapters/json-api-adapter/ajax-test.js | 8 +- tests/unit/adapters/rest-adapter/ajax-test.js | 18 +-- .../rest-adapter/detailed-message-test.js | 2 +- .../group-records-for-find-many-test.js | 23 +-- tests/unit/debug-test.js | 11 +- tests/unit/diff-array-test.js | 2 +- tests/unit/many-array-test.js | 8 +- tests/unit/model-test.js | 29 ++-- tests/unit/model/errors-test.js | 2 +- tests/unit/model/lifecycle-callbacks-test.js | 18 +-- tests/unit/model/merge-test.js | 12 +- tests/unit/model/relationships-test.js | 8 +- .../model/relationships/belongs-to-test.js | 7 +- .../unit/model/relationships/has-many-test.js | 33 ++-- .../model/relationships/record-array-test.js | 12 +- tests/unit/model/rollback-attributes-test.js | 46 +++--- tests/unit/private-test.js | 6 +- tests/unit/promise-proxies-test.js | 21 +-- .../adapter-populated-record-array-test.js | 10 +- .../filtered-record-array-test.js | 15 +- tests/unit/record-arrays/record-array-test.js | 22 +-- tests/unit/states-test.js | 5 +- tests/unit/store/adapter-interop-test.js | 44 +++--- tests/unit/store/asserts-test.js | 4 +- tests/unit/store/create-record-test.js | 12 +- tests/unit/store/finders-test.js | 8 +- tests/unit/store/has-model-for-test.js | 4 +- tests/unit/store/has-record-for-id-test.js | 7 +- tests/unit/store/lookup-test.js | 5 +- tests/unit/store/model-for-test.js | 8 +- tests/unit/store/peek-record-test.js | 7 +- tests/unit/store/push-test.js | 23 +-- tests/unit/store/serialize-test.js | 4 +- tests/unit/store/serializer-for-test.js | 5 +- tests/unit/store/unload-test.js | 19 +-- .../relationship-payload-manager-test.js | 8 +- .../relationship-payloads-test.js | 8 +- .../unit/system/snapshot-record-array-test.js | 10 +- tests/unit/transform/boolean-test.js | 2 +- tests/unit/transform/date-test.js | 2 +- tests/unit/transform/number-test.js | 2 +- tests/unit/transform/string-test.js | 2 +- tests/unit/utils-test.js | 17 +- 160 files changed, 1109 insertions(+), 1102 deletions(-) diff --git a/addon/-private/adapters/build-url-mixin.js b/addon/-private/adapters/build-url-mixin.js index bd3de1ce3e1..4a10181aacc 100644 --- a/addon/-private/adapters/build-url-mixin.js +++ b/addon/-private/adapters/build-url-mixin.js @@ -1,7 +1,8 @@ +import { camelize } from '@ember/string'; +import Mixin from '@ember/object/mixin'; +import { get } from '@ember/object'; import Ember from 'ember'; -const get = Ember.get; - /** WARNING: This interface is likely to change in order to accomodate https://github.com/emberjs/rfcs/pull/4 @@ -29,7 +30,7 @@ const get = Ember.get; @class BuildURLMixin @namespace DS */ -export default Ember.Mixin.create({ +export default Mixin.create({ /** Builds a URL for a given type and optional ID. @@ -434,7 +435,7 @@ export default Ember.Mixin.create({ @return {String} path **/ pathForType(modelName) { - let camelized = Ember.String.camelize(modelName); + let camelized = camelize(modelName); return Ember.String.pluralize(camelized); } }); diff --git a/addon/-private/adapters/errors.js b/addon/-private/adapters/errors.js index 65c22b0102d..16ad707c2c3 100644 --- a/addon/-private/adapters/errors.js +++ b/addon/-private/adapters/errors.js @@ -1,10 +1,10 @@ -import Ember from 'ember'; +import { makeArray } from '@ember/array'; +import { isPresent } from '@ember/utils'; +import EmberError from '@ember/error'; import { assert } from '@ember/debug'; import isEnabled from '../features'; -const EmberError = Ember.Error; - const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/; const SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/; const PRIMARY_ATTRIBUTE_KEY = 'base'; @@ -388,9 +388,9 @@ export const ServerError = extendedErrorsEnabled ? export function errorsHashToArray(errors) { let out = []; - if (Ember.isPresent(errors)) { + if (isPresent(errors)) { Object.keys(errors).forEach((key) => { - let messages = Ember.makeArray(errors[key]); + let messages = makeArray(errors[key]); for (let i = 0; i < messages.length; i++) { let title = 'Invalid Attribute'; let pointer = `/data/attributes/${key}`; @@ -455,7 +455,7 @@ export function errorsHashToArray(errors) { export function errorsArrayToHash(errors) { let out = {}; - if (Ember.isPresent(errors)) { + if (isPresent(errors)) { errors.forEach((error) => { if (error.source && error.source.pointer) { let key = error.source.pointer.match(SOURCE_POINTER_REGEXP); diff --git a/addon/-private/system/debug/debug-adapter.js b/addon/-private/system/debug/debug-adapter.js index 63df01ee251..abd9f6df50d 100644 --- a/addon/-private/system/debug/debug-adapter.js +++ b/addon/-private/system/debug/debug-adapter.js @@ -1,11 +1,14 @@ /** @module ember-data */ -import Ember from 'ember'; +import { addObserver, removeObserver } from '@ember/object/observers'; + +import { A } from '@ember/array'; +import DataAdapter from '@ember/debug/data-adapter'; +import { capitalize, underscore } from '@ember/string'; +import { assert } from '@ember/debug'; +import { get } from '@ember/object'; import Model from '../model/model'; -const capitalize = Ember.String.capitalize; -const underscore = Ember.String.underscore; -const { assert, get } = Ember; /* Extend `Ember.DataAdapter` with ED specific code. @@ -15,7 +18,7 @@ const { assert, get } = Ember; @extends Ember.DataAdapter @private */ -export default Ember.DataAdapter.extend({ +export default DataAdapter.extend({ getFilters() { return [ { name: 'isNew', desc: 'New' }, @@ -73,7 +76,7 @@ export default Ember.DataAdapter.extend({ getRecordKeywords(record) { let keywords = []; - let keys = Ember.A(['id']); + let keys = A(['id']); record.eachAttribute((key) => keys.push(key)); keys.forEach((key) => keywords.push(get(record, key))); return keywords; @@ -98,8 +101,8 @@ export default Ember.DataAdapter.extend({ }, observeRecord(record, recordUpdated) { - let releaseMethods = Ember.A(); - let keysToObserve = Ember.A(['id', 'isNew', 'hasDirtyAttributes']); + let releaseMethods = A(); + let keysToObserve = A(['id', 'isNew', 'hasDirtyAttributes']); record.eachAttribute((key) => keysToObserve.push(key)); let adapter = this; @@ -108,9 +111,9 @@ export default Ember.DataAdapter.extend({ let handler = function() { recordUpdated(adapter.wrapRecord(record)); }; - Ember.addObserver(record, key, handler); + addObserver(record, key, handler); releaseMethods.push(function() { - Ember.removeObserver(record, key, handler); + removeObserver(record, key, handler); }); }); diff --git a/addon/-private/system/is-array-like.js b/addon/-private/system/is-array-like.js index 3be11dac000..f442e8e9721 100644 --- a/addon/-private/system/is-array-like.js +++ b/addon/-private/system/is-array-like.js @@ -1,4 +1,5 @@ -import Ember from 'ember'; +import { typeOf } from '@ember/utils'; +import EmberArray from '@ember/array'; /* We're using this to detect arrays and "array-like" objects. @@ -13,9 +14,9 @@ import Ember from 'ember'; export default function isArrayLike(obj) { if (!obj || obj.setInterval) { return false; } if (Array.isArray(obj)) { return true; } - if (Ember.Array.detect(obj)) { return true; } + if (EmberArray.detect(obj)) { return true; } - let type = Ember.typeOf(obj); + let type = typeOf(obj); if ('array' === type) { return true; } if ((obj.length !== undefined) && 'object' === type) { return true; } return false; diff --git a/addon/-private/system/many-array.js b/addon/-private/system/many-array.js index 569263e1f5e..7ea140ff392 100644 --- a/addon/-private/system/many-array.js +++ b/addon/-private/system/many-array.js @@ -1,14 +1,16 @@ /** @module ember-data */ -import Ember from 'ember'; +import { all } from 'rsvp'; + +import Evented from '@ember/object/evented'; +import MutableArray from '@ember/array/mutable'; +import EmberObject, { get } from '@ember/object'; import { assert } from '@ember/debug'; import { PromiseArray } from "./promise-proxies"; import { _objectIsAlive } from "./store/common"; import diffArray from './diff-array'; -const { get } = Ember; - /** A `ManyArray` is a `MutableArray` that represents the contents of a has-many relationship. @@ -52,7 +54,7 @@ const { get } = Ember; @extends Ember.Object @uses Ember.MutableArray, Ember.Evented */ -export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { +export default EmberObject.extend(MutableArray, Evented, { init() { this._super(...arguments); @@ -260,7 +262,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, { save() { let manyArray = this; let promiseLabel = 'DS: ManyArray#save ' + get(this, 'type'); - let promise = Ember.RSVP.all(this.invoke("save"), promiseLabel). + let promise = all(this.invoke("save"), promiseLabel). then(() => manyArray, null, 'DS: ManyArray#save return ManyArray'); return PromiseArray.create({ promise }); diff --git a/addon/-private/system/model/errors.js b/addon/-private/system/model/errors.js index d9ceb6d3036..695a063fc7b 100644 --- a/addon/-private/system/model/errors.js +++ b/addon/-private/system/model/errors.js @@ -1,8 +1,12 @@ -import Ember from 'ember'; +import { mapBy, not } from '@ember/object/computed'; +import Evented from '@ember/object/evented'; +import ArrayProxy from '@ember/array/proxy'; +import { set, get, computed } from '@ember/object'; +import { isEmpty } from '@ember/utils'; +import { makeArray, A } from '@ember/array'; +import MapWithDefault from '@ember/map/with-default'; import { deprecate, warn } from '@ember/debug'; -const { get, set, isEmpty, makeArray, MapWithDefault } = Ember; - /** @module ember-data */ @@ -82,7 +86,7 @@ const { get, set, isEmpty, makeArray, MapWithDefault } = Ember; @uses Ember.Enumerable @uses Ember.Evented */ -export default Ember.ArrayProxy.extend(Ember.Evented, { +export default ArrayProxy.extend(Evented, { /** Register with target handler @@ -120,10 +124,10 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @type {Ember.MapWithDefault} @private */ - errorsByAttributeName: Ember.computed(function() { + errorsByAttributeName: computed(function() { return MapWithDefault.create({ defaultValue() { - return Ember.A(); + return A(); } }); }), @@ -165,15 +169,15 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @property messages @type {Array} */ - messages: Ember.computed.mapBy('content', 'message'), + messages: mapBy('content', 'message'), /** @property content @type {Array} @private */ - content: Ember.computed(function() { - return Ember.A(); + content: computed(function() { + return A(); }), /** @@ -199,7 +203,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { @type {Boolean} @readOnly */ - isEmpty: Ember.computed.not('length').readOnly(), + isEmpty: not('length').readOnly(), /** Adds error messages to a given attribute and sends @@ -383,7 +387,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { if (get(this, 'isEmpty')) { return; } let errorsByAttributeName = get(this, 'errorsByAttributeName'); - let attributes = Ember.A(); + let attributes = A(); errorsByAttributeName.forEach(function(_, attribute) { attributes.push(attribute); @@ -394,7 +398,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { this.notifyPropertyChange(attribute); }, this); - Ember.ArrayProxy.prototype.clear.call(this); + ArrayProxy.prototype.clear.call(this); }, diff --git a/addon/-private/system/model/internal-model.js b/addon/-private/system/model/internal-model.js index 3fbe60771d4..3a74691a61e 100644 --- a/addon/-private/system/model/internal-model.js +++ b/addon/-private/system/model/internal-model.js @@ -1,6 +1,14 @@ +import { assign as emberAssign, merge } from '@ember/polyfills'; +import { set, get } from '@ember/object'; +import { copy } from '@ember/object/internals'; +import EmberError from '@ember/error'; +import { isEqual, isEmpty } from '@ember/utils'; +import { setOwner } from '@ember/application'; +import { run } from '@ember/runloop'; +import RSVP, { Promise } from 'rsvp'; import Ember from 'ember'; import { DEBUG } from '@glimmer/env'; -import { assert } from '@ember/debug'; +import { assert, inspect } from '@ember/debug'; import RootState from "./states"; import Relationships from "../relationships/state/create"; import Snapshot from "../snapshot"; @@ -15,32 +23,18 @@ import { HasManyReference } from "../references"; -const { - get, - set, - copy, - Error: EmberError, - inspect, - isEmpty, - isEqual, - setOwner, - run, - RSVP, - RSVP: { Promise } -} = Ember; - -const assign = Ember.assign || Ember.merge; +const assign = emberAssign || merge; /* The TransitionChainMap caches the `state.enters`, `state.setups`, and final state reached when transitioning from one state to another, so that future transitions can replay the transition without needing to walk the state tree, collect these hook calls and determine - the state to transition into. + the state to transition into. - A future optimization would be to build a single chained method out of the collected enters - and setups. It may also be faster to do a two level cache (from: { to }) instead of caching based - on a key that adds the two together. - */ + A future optimization would be to build a single chained method out of the collected enters + and setups. It may also be faster to do a two level cache (from: { to }) instead of caching based + on a key that adds the two together. +*/ const TransitionChainMap = Object.create(null); const _extractPivotNameCache = Object.create(null); diff --git a/addon/-private/system/model/model.js b/addon/-private/system/model/model.js index a900349f746..2c2dcf11428 100644 --- a/addon/-private/system/model/model.js +++ b/addon/-private/system/model/model.js @@ -1,3 +1,14 @@ +import ComputedProperty from '@ember/object/computed'; +import { setOwner } from '@ember/application'; +import { isNone } from '@ember/utils'; +import EmberError from '@ember/error'; +import Evented from '@ember/object/evented'; +import EmberObject, { + computed, + get, + observer +} from '@ember/object'; +import Map from '@ember/map'; import Ember from 'ember'; import { DEBUG } from '@glimmer/env'; import { assert, deprecate, warn } from '@ember/debug'; @@ -11,12 +22,6 @@ import { relationshipsDescriptor } from '../relationships/ext'; -const { - get, - computed, - Map -} = Ember; - /** @module ember-data */ @@ -81,7 +86,7 @@ const retrieveFromCurrentState = computed('currentState', function(key) { @extends Ember.Object @uses Ember.Evented */ -const Model = Ember.Object.extend(Ember.Evented, { +const Model = EmberObject.extend(Evented, { _internalModel: null, store: null, __defineNonEnumerable(property) { @@ -973,7 +978,7 @@ const Model = Ember.Object.extend(Ember.Evented, { return this._internalModel.referenceFor('hasMany', name); }, - setId: Ember.observer('id', function () { + setId: observer('id', function () { this._internalModel.setId(this.get('id')); }), @@ -1137,7 +1142,7 @@ if (DEBUG) { this._super(...arguments); if (!this._internalModel) { - throw new Ember.Error('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.'); + throw new EmberError('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.'); } } }); @@ -1232,7 +1237,7 @@ Model.reopenClass({ return relationship && store.modelFor(relationship.type); }, - inverseMap: Ember.computed(function() { + inverseMap: computed(function() { return Object.create(null); }), @@ -1309,10 +1314,10 @@ Model.reopenClass({ //If inverse is specified manually, return the inverse if (options.inverse) { inverseName = options.inverse; - inverse = Ember.get(inverseType, 'relationshipsByName').get(inverseName); + inverse = get(inverseType, 'relationshipsByName').get(inverseName); assert("We found no inverse relationships by the name of '" + inverseName + "' on the '" + inverseType.modelName + - "' model. This is most likely due to a missing attribute on your model definition.", !Ember.isNone(inverse)); + "' model. This is most likely due to a missing attribute on your model definition.", !isNone(inverse)); inverseKind = inverse.kind; } else { @@ -1432,7 +1437,7 @@ Model.reopenClass({ @type Object @readOnly */ - relationshipNames: Ember.computed(function() { + relationshipNames: computed(function() { let names = { hasMany: [], belongsTo: [] @@ -1561,7 +1566,7 @@ Model.reopenClass({ @type Ember.Map @readOnly */ - fields: Ember.computed(function() { + fields: computed(function() { let map = Map.create(); this.eachComputedProperty((name, meta) => { @@ -1670,7 +1675,7 @@ Model.reopenClass({ @type {Ember.Map} @readOnly */ - attributes: Ember.computed(function() { + attributes: computed(function() { let map = Map.create(); this.eachComputedProperty((name, meta) => { @@ -1723,7 +1728,7 @@ Model.reopenClass({ @type {Ember.Map} @readOnly */ - transformedAttributes: Ember.computed(function() { + transformedAttributes: computed(function() { let map = Map.create(); this.eachAttribute((key, meta) => { @@ -1840,7 +1845,7 @@ Model.reopenClass({ // deprecation is actually created via an `.extend` of the factory // inside the container itself, but that only happens on models // with MODEL_FACTORY_INJECTIONS enabled :( -if (Ember.setOwner) { +if (setOwner) { Object.defineProperty(Model.prototype, 'container', { configurable: true, enumerable: false, @@ -1917,7 +1922,7 @@ if (DEBUG) { */ didDefineProperty(proto, key, value) { // Check if the value being set is a computed property. - if (value instanceof Ember.ComputedProperty) { + if (value instanceof ComputedProperty) { // If it is, get the metadata for the relationship. This is // populated by the `DS.belongsTo` helper when it is creating diff --git a/addon/-private/system/normalize-model-name.js b/addon/-private/system/normalize-model-name.js index 07885e8a552..c70285c8c73 100644 --- a/addon/-private/system/normalize-model-name.js +++ b/addon/-private/system/normalize-model-name.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import { dasherize } from '@ember/string'; // All modelNames are dasherized internally. Changing this function may // require changes to other normalization hooks (such as typeForRoot). @@ -14,5 +14,5 @@ import Ember from 'ember'; @for DS */ export default function normalizeModelName(modelName) { - return Ember.String.dasherize(modelName); + return dasherize(modelName); } diff --git a/addon/-private/system/ordered-set.js b/addon/-private/system/ordered-set.js index 766f722a0a3..0577ec61664 100644 --- a/addon/-private/system/ordered-set.js +++ b/addon/-private/system/ordered-set.js @@ -1,7 +1,7 @@ +import { guidFor } from '@ember/object/internals'; import Ember from 'ember'; const EmberOrderedSet = Ember.OrderedSet; -const guidFor = Ember.guidFor; export default function OrderedSet() { this._super$constructor(); diff --git a/addon/-private/system/promise-proxies.js b/addon/-private/system/promise-proxies.js index 6999a9c991c..fcd47185897 100644 --- a/addon/-private/system/promise-proxies.js +++ b/addon/-private/system/promise-proxies.js @@ -1,8 +1,10 @@ -import Ember from 'ember'; +import ObjectProxy from '@ember/object/proxy'; +import PromiseProxyMixin from '@ember/object/promise-proxy-mixin'; +import ArrayProxy from '@ember/array/proxy'; +import { get } from '@ember/object'; +import { Promise } from 'rsvp'; import { assert } from '@ember/debug'; -const { get , RSVP: { Promise }} = Ember; - /** A `PromiseArray` is an object that acts like both an `Ember.Array` and a promise. When the promise is resolved the resulting value @@ -32,7 +34,7 @@ const { get , RSVP: { Promise }} = Ember; @extends Ember.ArrayProxy @uses Ember.PromiseProxyMixin */ -export const PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin); +export const PromiseArray = ArrayProxy.extend(PromiseProxyMixin); /** A `PromiseObject` is an object that acts like both an `Ember.Object` @@ -63,7 +65,7 @@ export const PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin); @extends Ember.ObjectProxy @uses Ember.PromiseProxyMixin */ -export let PromiseObject = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); +export let PromiseObject = ObjectProxy.extend(PromiseProxyMixin); export function promiseObject(promise, label) { return PromiseObject.create({ diff --git a/addon/-private/system/record-array-manager.js b/addon/-private/system/record-array-manager.js index 483e7766502..9802e02ce79 100644 --- a/addon/-private/system/record-array-manager.js +++ b/addon/-private/system/record-array-manager.js @@ -2,7 +2,10 @@ @module ember-data */ -import Ember from 'ember'; +import { A } from '@ember/array'; + +import { set, get } from '@ember/object'; +import { run as emberRun } from '@ember/runloop'; import { RecordArray, FilteredRecordArray, @@ -12,12 +15,6 @@ import { import cloneNull from "./clone-null"; import { assert } from '@ember/debug'; -const { - get, - set, - run: emberRun -} = Ember; - const { _flush, array_flatten, @@ -308,7 +305,7 @@ export default class RecordArrayManager { let array = RecordArray.create({ modelName, - content: Ember.A(content || []), + content: A(content || []), store: this.store, isLoaded: true, manager: this @@ -337,7 +334,7 @@ export default class RecordArrayManager { let array = FilteredRecordArray.create({ query, modelName, - content: Ember.A(), + content: A(), store: this.store, manager: this, filterFunction: filter @@ -365,7 +362,7 @@ export default class RecordArrayManager { array = AdapterPopulatedRecordArray.create({ modelName, query: query, - content: Ember.A(internalModels), + content: A(internalModels), store: this.store, manager: this, isLoaded: true, @@ -379,7 +376,7 @@ export default class RecordArrayManager { array = AdapterPopulatedRecordArray.create({ modelName, query: query, - content: Ember.A(), + content: A(), store: this.store, manager: this }); diff --git a/addon/-private/system/record-arrays/adapter-populated-record-array.js b/addon/-private/system/record-arrays/adapter-populated-record-array.js index 240d704ae2b..8ef73763c8c 100644 --- a/addon/-private/system/record-arrays/adapter-populated-record-array.js +++ b/addon/-private/system/record-arrays/adapter-populated-record-array.js @@ -1,14 +1,10 @@ -import Ember from 'ember'; +import { once } from '@ember/runloop'; +import { A } from '@ember/array'; +import { get } from '@ember/object'; import RecordArray from "./record-array"; import cloneNull from "../clone-null"; import { associateWithRecordArray } from '../record-array-manager'; -/** - @module ember-data -*/ - -const { get } = Ember; - /** Represents an ordered list of records whose order and membership is determined by the adapter. For example, a query sent to the adapter @@ -49,7 +45,7 @@ const { get } = Ember; export default RecordArray.extend({ init() { // yes we are touching `this` before super, but ArrayProxy has a bug that requires this. - this.set('content', this.get('content') || Ember.A()); + this.set('content', this.get('content') || A()); this._super(...arguments); this.query = this.query || null; @@ -91,7 +87,7 @@ export default RecordArray.extend({ associateWithRecordArray(internalModels, this); // TODO: should triggering didLoad event be the last action of the runLoop? - Ember.run.once(this, 'trigger', 'didLoad'); + once(this, 'trigger', 'didLoad'); heimdall.stop(token); } }); diff --git a/addon/-private/system/record-arrays/filtered-record-array.js b/addon/-private/system/record-arrays/filtered-record-array.js index 3fb9eaac50f..66ab0ff8016 100644 --- a/addon/-private/system/record-arrays/filtered-record-array.js +++ b/addon/-private/system/record-arrays/filtered-record-array.js @@ -1,12 +1,7 @@ -import Ember from 'ember'; +import { once } from '@ember/runloop'; +import { get, observer } from '@ember/object'; import RecordArray from "./record-array"; -/** - @module ember-data -*/ - -const { get } = Ember; - /** Represents a list of records whose membership is determined by the store. As records are created, loaded, or modified, the store @@ -66,7 +61,7 @@ export default RecordArray.extend({ get(this, 'manager').updateFilter(this, this.modelName, get(this, 'filterFunction')); }, - updateFilter: Ember.observer('filterFunction', function() { - Ember.run.once(this, this._updateFilter); + updateFilter: observer('filterFunction', function() { + once(this, this._updateFilter); }) }); diff --git a/addon/-private/system/record-arrays/record-array.js b/addon/-private/system/record-arrays/record-array.js index 0b2d42a82d5..220e17f01d2 100644 --- a/addon/-private/system/record-arrays/record-array.js +++ b/addon/-private/system/record-arrays/record-array.js @@ -2,12 +2,14 @@ @module ember-data */ -import Ember from 'ember'; +import Evented from '@ember/object/evented'; + +import ArrayProxy from '@ember/array/proxy'; +import { set, get, computed } from '@ember/object'; +import { Promise } from 'rsvp'; import { PromiseArray } from "../promise-proxies"; import SnapshotRecordArray from "../snapshot-record-array"; -const { computed, get, set, RSVP: { Promise } } = Ember; - /** A record array is an array that contains records of a certain modelName. The record array materializes records as needed when they are retrieved for the first @@ -21,7 +23,7 @@ const { computed, get, set, RSVP: { Promise } } = Ember; @uses Ember.Evented */ -export default Ember.ArrayProxy.extend(Ember.Evented, { +export default ArrayProxy.extend(Evented, { init() { this._super(...arguments); diff --git a/addon/-private/system/references/belongs-to.js b/addon/-private/system/references/belongs-to.js index e81a5b0a6af..745ff4d556b 100644 --- a/addon/-private/system/references/belongs-to.js +++ b/addon/-private/system/references/belongs-to.js @@ -1,5 +1,5 @@ +import { resolve } from 'rsvp'; import Model from '../model/model'; -import Ember from 'ember'; import Reference from './reference'; import isEnabled from '../../features'; @@ -240,7 +240,7 @@ BelongsToReference.prototype.meta = function() { @return {Promise} A promise that resolves with the new value in this belongs-to relationship. */ BelongsToReference.prototype.push = function(objectOrPromise) { - return Ember.RSVP.resolve(objectOrPromise).then((data) => { + return resolve(objectOrPromise).then((data) => { let record; if (data instanceof Model) { diff --git a/addon/-private/system/references/has-many.js b/addon/-private/system/references/has-many.js index 9f08a7f5e77..e60cc5b7f47 100644 --- a/addon/-private/system/references/has-many.js +++ b/addon/-private/system/references/has-many.js @@ -1,4 +1,6 @@ -import Ember from 'ember'; +import { A } from '@ember/array'; +import { resolve } from 'rsvp'; +import { get } from '@ember/object'; import Reference from './reference'; import { DEBUG } from '@glimmer/env'; import { deprecate } from '@ember/debug'; @@ -6,11 +8,6 @@ import { assertPolymorphicType } from 'ember-data/-debug'; import isEnabled from '../../features'; -const { - RSVP: { resolve }, - get -} = Ember; - /** A HasManyReference is a low level API that allows users and addon author to perform meta-operations on a has-many relationship. @@ -284,7 +281,7 @@ HasManyReference.prototype.push = function(objectOrPromise) { }); } else { let records = this.store.push(payload); - internalModels = Ember.A(records).mapBy('_internalModel'); + internalModels = A(records).mapBy('_internalModel'); if (DEBUG) { internalModels.forEach((internalModel) => { diff --git a/addon/-private/system/references/record.js b/addon/-private/system/references/record.js index 6b2b77b0502..bace8a75d6d 100644 --- a/addon/-private/system/references/record.js +++ b/addon/-private/system/references/record.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import { resolve } from 'rsvp'; import Reference from './reference'; /** @@ -90,7 +90,7 @@ RecordReference.prototype.remoteType = function() { @return Promise a promise for the value (record or relationship) */ RecordReference.prototype.push = function(objectOrPromise) { - return Ember.RSVP.resolve(objectOrPromise).then((data) => { + return resolve(objectOrPromise).then((data) => { return this.store.push(data); }); }; diff --git a/addon/-private/system/relationship-meta.js b/addon/-private/system/relationship-meta.js index bb9763ae145..740eff604ee 100644 --- a/addon/-private/system/relationship-meta.js +++ b/addon/-private/system/relationship-meta.js @@ -1,4 +1,4 @@ -import {singularize} from 'ember-inflector'; +import { singularize } from 'ember-inflector'; import normalizeModelName from './normalize-model-name'; import { DEBUG } from '@glimmer/env'; diff --git a/addon/-private/system/relationships/belongs-to.js b/addon/-private/system/relationships/belongs-to.js index 445d01ffb4e..043d468f02d 100644 --- a/addon/-private/system/relationships/belongs-to.js +++ b/addon/-private/system/relationships/belongs-to.js @@ -1,5 +1,5 @@ -import Ember from 'ember'; -import { assert, warn } from '@ember/debug'; +import { computed } from '@ember/object'; +import { assert, warn, inspect } from '@ember/debug'; import normalizeModelName from "../normalize-model-name"; /** @@ -88,7 +88,7 @@ export default function belongsTo(modelName, options) { userEnteredModelName = normalizeModelName(userEnteredModelName); } - assert("The first argument to DS.belongsTo must be a string representing a model type key, not an instance of " + Ember.inspect(userEnteredModelName) + ". E.g., to define a relation to the Person model, use DS.belongsTo('person')", typeof userEnteredModelName === 'string' || typeof userEnteredModelName === 'undefined'); + assert("The first argument to DS.belongsTo must be a string representing a model type key, not an instance of " + inspect(userEnteredModelName) + ". E.g., to define a relation to the Person model, use DS.belongsTo('person')", typeof userEnteredModelName === 'string' || typeof userEnteredModelName === 'undefined'); opts = opts || {}; @@ -101,7 +101,7 @@ export default function belongsTo(modelName, options) { key: null }; - return Ember.computed({ + return computed({ get(key) { if (opts.hasOwnProperty('serialize')) { warn(`You provided a serialize option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.Serializer and it's implementations https://emberjs.com/api/data/classes/DS.Serializer.html`, false, { diff --git a/addon/-private/system/relationships/ext.js b/addon/-private/system/relationships/ext.js index 528930717a6..872d9f0e1f2 100644 --- a/addon/-private/system/relationships/ext.js +++ b/addon/-private/system/relationships/ext.js @@ -1,3 +1,7 @@ +import { A } from '@ember/array'; +import { computed } from '@ember/object'; +import MapWithDefault from '@ember/map/with-default'; +import Map from '@ember/map'; import Ember from 'ember'; import { assert } from '@ember/debug'; import { @@ -5,10 +9,7 @@ import { relationshipFromMeta } from "../relationship-meta"; -const Map = Ember.Map; -const MapWithDefault = Ember.MapWithDefault; - -export const relationshipsDescriptor = Ember.computed(function() { +export const relationshipsDescriptor = computed(function() { if (Ember.testing === true && relationshipsDescriptor._cacheable === true) { relationshipsDescriptor._cacheable = false; } @@ -35,13 +36,13 @@ export const relationshipsDescriptor = Ember.computed(function() { return map; }).readOnly(); -export const relatedTypesDescriptor = Ember.computed(function() { +export const relatedTypesDescriptor = computed(function() { if (Ember.testing === true && relatedTypesDescriptor._cacheable === true) { relatedTypesDescriptor._cacheable = false; } let modelName; - let types = Ember.A(); + let types = A(); // Loop through each computed property on the class, // and create an array of the unique types involved @@ -63,7 +64,7 @@ export const relatedTypesDescriptor = Ember.computed(function() { return types; }).readOnly(); -export const relationshipsByNameDescriptor = Ember.computed(function() { +export const relationshipsByNameDescriptor = computed(function() { let map = Map.create(); this.eachComputedProperty((name, meta) => { diff --git a/addon/-private/system/relationships/has-many.js b/addon/-private/system/relationships/has-many.js index 7327331aaf5..ed353e3bd27 100644 --- a/addon/-private/system/relationships/has-many.js +++ b/addon/-private/system/relationships/has-many.js @@ -2,13 +2,13 @@ @module ember-data */ -import Ember from 'ember'; -import { assert } from '@ember/debug'; +import { A } from '@ember/array'; + +import { get, computed } from '@ember/object'; +import { assert, inspect } from '@ember/debug'; import normalizeModelName from "../normalize-model-name"; import isArrayLike from "../is-array-like"; -const { get } = Ember; - /** `DS.hasMany` is used to define One-To-Many and Many-To-Many relationships on a [DS.Model](/api/data/classes/DS.Model.html). @@ -121,7 +121,7 @@ export default function hasMany(type, options) { type = undefined; } - assert(`The first argument to DS.hasMany must be a string representing a model type key, not an instance of ${Ember.inspect(type)}. E.g., to define a relation to the Comment model, use DS.hasMany('comment')`, typeof type === 'string' || typeof type === 'undefined'); + assert(`The first argument to DS.hasMany must be a string representing a model type key, not an instance of ${inspect(type)}. E.g., to define a relation to the Comment model, use DS.hasMany('comment')`, typeof type === 'string' || typeof type === 'undefined'); options = options || {}; @@ -142,14 +142,14 @@ export default function hasMany(type, options) { key: null }; - return Ember.computed({ + return computed({ get(key) { return this._internalModel._relationships.get(key).getRecords(); }, set(key, records) { assert(`You must pass an array of records to set a hasMany relationship`, isArrayLike(records)); - assert(`All elements of a hasMany relationship must be instances of DS.Model, you passed ${Ember.inspect(records)}`, (function() { - return Ember.A(records).every((record) => record.hasOwnProperty('_internalModel') === true); + assert(`All elements of a hasMany relationship must be instances of DS.Model, you passed ${inspect(records)}`, (function() { + return A(records).every((record) => record.hasOwnProperty('_internalModel') === true); })()); let relationship = this._internalModel._relationships.get(key); diff --git a/addon/-private/system/relationships/relationship-payloads-manager.js b/addon/-private/system/relationships/relationship-payloads-manager.js index 60f939e3dfb..3bf03430a0b 100644 --- a/addon/-private/system/relationships/relationship-payloads-manager.js +++ b/addon/-private/system/relationships/relationship-payloads-manager.js @@ -1,8 +1,6 @@ -import Ember from 'ember'; +import { get } from '@ember/object'; import RelationshipPayloads from './relationship-payloads'; -const get = Ember.get; - /** Manages relationship payloads for a given store, for uninitialized relationships. Acts as a single source of truth (of payloads) for both sides diff --git a/addon/-private/system/relationships/state/belongs-to.js b/addon/-private/system/relationships/state/belongs-to.js index 79ab00e7700..82a4d968856 100644 --- a/addon/-private/system/relationships/state/belongs-to.js +++ b/addon/-private/system/relationships/state/belongs-to.js @@ -1,7 +1,5 @@ -import Ember from 'ember'; -import { - assert -} from '@ember/debug'; +import { Promise as EmberPromise } from 'rsvp'; +import { assert, inspect } from '@ember/debug'; import { assertPolymorphicType } from 'ember-data/-debug'; import { PromiseObject @@ -131,7 +129,7 @@ export default class BelongsToRelationship extends Relationship { if (this.inverseInternalModel) { return this.store._findByInternalModel(this.inverseInternalModel); } else { - return Ember.RSVP.Promise.resolve(null); + return EmberPromise.resolve(null); } } @@ -188,7 +186,7 @@ export default class BelongsToRelationship extends Relationship { } updateData(data, initial) { - assert(`Ember Data expected the data for the ${this.key} relationship on a ${this.internalModel.toString()} to be in a JSON API format and include an \`id\` and \`type\` property but it found ${Ember.inspect(data)}. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`, data === null || data.id !== undefined && data.type !== undefined); + assert(`Ember Data expected the data for the ${this.key} relationship on a ${this.internalModel.toString()} to be in a JSON API format and include an \`id\` and \`type\` property but it found ${inspect(data)}. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`, data === null || data.id !== undefined && data.type !== undefined); let internalModel = this.store._pushResourceIdentifier(this, data); if (initial) { this.setInitialCanonicalInternalModel(internalModel); diff --git a/addon/-private/system/relationships/state/create.js b/addon/-private/system/relationships/state/create.js index 0acc2b86adf..1039683f91e 100644 --- a/addon/-private/system/relationships/state/create.js +++ b/addon/-private/system/relationships/state/create.js @@ -1,10 +1,8 @@ -import Ember from 'ember'; +import { get } from '@ember/object'; import ManyRelationship from "./has-many"; import BelongsToRelationship from "./belongs-to"; import { DEBUG } from '@glimmer/env'; -const { get } = Ember; - function shouldFindInverse(relationshipMeta) { let options = relationshipMeta.options; return !(options && options.inverse === null); diff --git a/addon/-private/system/relationships/state/relationship.js b/addon/-private/system/relationships/state/relationship.js index 8a6893c4f79..1922da783e9 100644 --- a/addon/-private/system/relationships/state/relationship.js +++ b/addon/-private/system/relationships/state/relationship.js @@ -1,10 +1,9 @@ /* global heimdall */ +import { guidFor } from '@ember/object/internals'; + import { assert, warn } from '@ember/debug'; import OrderedSet from '../../ordered-set'; import _normalizeLink from '../../normalize-link'; -import Ember from 'ember'; - -const { guidFor } = Ember; const { addCanonicalInternalModel, diff --git a/addon/-private/system/snapshot.js b/addon/-private/system/snapshot.js index 646f79f9148..98f4842d536 100644 --- a/addon/-private/system/snapshot.js +++ b/addon/-private/system/snapshot.js @@ -2,11 +2,11 @@ @module ember-data */ -import Ember from 'ember'; +import { copy } from '@ember/object/internals'; -const { - get -} = Ember; +import { inspect } from '@ember/debug'; +import EmberError from '@ember/error'; +import { get } from '@ember/object'; /** @class Snapshot @@ -110,7 +110,7 @@ export default class Snapshot { if (keyName in this._attributes) { return this._attributes[keyName]; } - throw new Ember.Error("Model '" + Ember.inspect(this.record) + "' has no attribute named '" + keyName + "' defined."); + throw new EmberError("Model '" + inspect(this.record) + "' has no attribute named '" + keyName + "' defined."); } /** @@ -127,7 +127,7 @@ export default class Snapshot { @return {Object} All attributes of the current snapshot */ attributes() { - return Ember.copy(this._attributes); + return copy(this._attributes); } /** @@ -150,7 +150,7 @@ export default class Snapshot { for (let i=0, length = changedAttributeKeys.length; i < length; i++) { let key = changedAttributeKeys[i]; - changedAttributes[key] = Ember.copy(this._changedAttributes[key]); + changedAttributes[key] = copy(this._changedAttributes[key]); } return changedAttributes; @@ -206,7 +206,7 @@ export default class Snapshot { relationship = this._internalModel._relationships.get(keyName); if (!(relationship && relationship.relationshipMeta.kind === 'belongsTo')) { - throw new Ember.Error("Model '" + Ember.inspect(this.record) + "' has no belongsTo relationship named '" + keyName + "' defined."); + throw new EmberError("Model '" + inspect(this.record) + "' has no belongsTo relationship named '" + keyName + "' defined."); } hasData = get(relationship, 'hasData'); @@ -277,7 +277,7 @@ export default class Snapshot { relationship = this._internalModel._relationships.get(keyName); if (!(relationship && relationship.relationshipMeta.kind === 'hasMany')) { - throw new Ember.Error("Model '" + Ember.inspect(this.record) + "' has no hasMany relationship named '" + keyName + "' defined."); + throw new EmberError("Model '" + inspect(this.record) + "' has no hasMany relationship named '" + keyName + "' defined."); } hasData = get(relationship, 'hasData'); diff --git a/addon/-private/system/store.js b/addon/-private/system/store.js index ac30e54c1cc..0009469ec4a 100644 --- a/addon/-private/system/store.js +++ b/addon/-private/system/store.js @@ -2,14 +2,21 @@ @module ember-data */ +import { A } from '@ember/array'; + +import { copy } from '@ember/object/internals'; +import EmberError from '@ember/error'; +import MapWithDefault from '@ember/map/with-default'; +import { run as emberRun } from '@ember/runloop'; +import { set, get, computed } from '@ember/object'; +import RSVP from 'rsvp'; +import Service from '@ember/service'; +import { typeOf, isPresent, isNone } from '@ember/utils'; + import Ember from 'ember'; import { InvalidError } from '../adapters/errors'; import { instrument } from 'ember-data/-debug'; -import { - assert, - deprecate, - warn -} from '@ember/debug'; +import { assert, deprecate, warn, inspect } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; import Model from './model/model'; import normalizeModelName from "./normalize-model-name"; @@ -50,22 +57,8 @@ import isEnabled from '../features'; const badIdFormatAssertion = '`id` passed to `findRecord()` has to be non-empty string or number'; const { - A, _Backburner: Backburner, - computed, - copy, - ENV, - Error: EmberError, - get, - inspect, - isNone, - isPresent, - MapWithDefault, - run: emberRun, - set, - RSVP, - Service, - typeOf + ENV } = Ember; const { Promise } = RSVP; diff --git a/addon/-private/system/store/common.js b/addon/-private/system/store/common.js index 8ce2777e417..e0548b71467 100644 --- a/addon/-private/system/store/common.js +++ b/addon/-private/system/store/common.js @@ -1,8 +1,4 @@ -import Ember from 'ember'; - -const { - get -} = Ember; +import { get } from '@ember/object'; const { __bind, diff --git a/addon/-private/system/store/container-instance-cache.js b/addon/-private/system/store/container-instance-cache.js index 82768c827ae..ba0311d6cca 100644 --- a/addon/-private/system/store/container-instance-cache.js +++ b/addon/-private/system/store/container-instance-cache.js @@ -1,6 +1,5 @@ /* global heimdall */ -import Ember from 'ember'; -const { set } = Ember; +import { set } from '@ember/object'; const { __get, diff --git a/addon/-private/system/store/finders.js b/addon/-private/system/store/finders.js index 30c57ffe73f..0103a0084a1 100644 --- a/addon/-private/system/store/finders.js +++ b/addon/-private/system/store/finders.js @@ -1,4 +1,5 @@ -import Ember from 'ember'; +import { A } from '@ember/array'; +import { Promise } from 'rsvp'; import { assert, warn } from '@ember/debug'; import { _bind, @@ -9,8 +10,6 @@ import { import { normalizeResponseHelper } from "./serializer-response"; import { serializerForAdapter } from "./serializers"; -const { Promise } = Ember.RSVP; - function payloadIsNotBlank(adapterPayload) { if (Array.isArray(adapterPayload)) { return true; @@ -50,7 +49,7 @@ export function _find(adapter, store, modelClass, id, internalModel, options) { } export function _findMany(adapter, store, modelName, ids, internalModels) { - let snapshots = Ember.A(internalModels).invoke('createSnapshot'); + let snapshots = A(internalModels).invoke('createSnapshot'); let modelClass = store.modelFor(modelName); // `adapter.findMany` gets the modelClass still let promise = adapter.findMany(store, modelClass, ids, snapshots); let label = `DS: Handle Adapter#findMany of '${modelName}'`; diff --git a/addon/-private/system/store/serializer-response.js b/addon/-private/system/store/serializer-response.js index 1a264253d49..8a75dde9644 100644 --- a/addon/-private/system/store/serializer-response.js +++ b/addon/-private/system/store/serializer-response.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import { isEmpty } from '@ember/utils'; import { assert } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; @@ -79,7 +79,7 @@ export function normalizeResponseHelper(serializer, store, modelClass, payload, if (DEBUG) { validationErrors = validateDocumentStructure(normalizedResponse); } - assert(`normalizeResponse must return a valid JSON API document:\n\t* ${validationErrors.join('\n\t* ')}`, Ember.isEmpty(validationErrors)); + assert(`normalizeResponse must return a valid JSON API document:\n\t* ${validationErrors.join('\n\t* ')}`, isEmpty(validationErrors)); return normalizedResponse; } diff --git a/addon/-private/utils.js b/addon/-private/utils.js index 138835394ed..eabd86938d5 100644 --- a/addon/-private/utils.js +++ b/addon/-private/utils.js @@ -1,6 +1,5 @@ -import Ember from 'ember'; - -const get = Ember.get; +import { getOwner } from '@ember/application'; +import { get } from '@ember/object'; /* Check if the passed model has a `type` attribute or a relationship named `type`. @@ -20,8 +19,8 @@ function modelHasAttributeOrRelationshipNamedType(modelClass) { function getOwner(context) { let owner; - if (Ember.getOwner) { - owner = Ember.getOwner(context); + if (getOwner) { + owner = getOwner(context); } else if (context.container) { owner = context.container; } diff --git a/addon/adapter.js b/addon/adapter.js index 6ebb94e6405..8ba3dce104e 100644 --- a/addon/adapter.js +++ b/addon/adapter.js @@ -2,7 +2,7 @@ @module ember-data */ -import Ember from 'ember'; +import EmberObject from '@ember/object'; /** An adapter is an object that receives requests from a store and @@ -60,7 +60,7 @@ import Ember from 'ember'; @extends Ember.Object */ -export default Ember.Object.extend({ +export default EmberObject.extend({ /** If you would like your adapter to use a custom serializer you can diff --git a/addon/adapters/json-api.js b/addon/adapters/json-api.js index 144e15caa69..6cb08e2fb2b 100644 --- a/addon/adapters/json-api.js +++ b/addon/adapters/json-api.js @@ -3,6 +3,10 @@ @module ember-data */ +import { dasherize } from '@ember/string'; + +import $ from 'jquery'; + import Ember from 'ember'; import RESTAdapter from "./rest"; import { isEnabled } from '../-private'; @@ -169,7 +173,7 @@ const JSONAPIAdapter = RESTAdapter.extend({ let token = heimdall.start('json.parse'); let json; try { - json = Ember.$.parseJSON(payload); + json = $.parseJSON(payload); } catch (e) { json = payload; } @@ -257,7 +261,7 @@ const JSONAPIAdapter = RESTAdapter.extend({ }, pathForType(modelName) { - let dasherized = Ember.String.dasherize(modelName); + let dasherized = dasherize(modelName); return Ember.String.pluralize(dasherized); }, diff --git a/addon/adapters/rest.js b/addon/adapters/rest.js index 6ab765533ea..2dbd02e6737 100644 --- a/addon/adapters/rest.js +++ b/addon/adapters/rest.js @@ -3,7 +3,12 @@ @module ember-data */ -import Ember from 'ember'; +import $ from 'jquery'; + +import { Promise as EmberPromise } from 'rsvp'; +import MapWithDefault from '@ember/map/with-default'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; import Adapter from "../adapter"; import { parseResponseHeaders, @@ -23,13 +28,7 @@ import { instrument } from 'ember-data/-debug'; import { warn, deprecate } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; -const { - MapWithDefault, - get, - run -} = Ember; - -const Promise = Ember.RSVP.Promise; +const Promise = EmberPromise; /** The REST adapter allows your store to communicate with an HTTP server by @@ -1084,7 +1083,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { @param {Object} options jQuery ajax options to be used for the ajax request */ _ajaxRequest(options) { - Ember.$.ajax(options); + $.ajax(options); }, /** @@ -1108,7 +1107,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { let token = heimdall.start('json.parse'); let json; try { - json = Ember.$.parseJSON(payload); + json = $.parseJSON(payload); } catch (e) { json = payload; } @@ -1143,7 +1142,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, { let json = responseText; try { - json = Ember.$.parseJSON(responseText); + json = $.parseJSON(responseText); } catch (e) { // ignored } @@ -1466,7 +1465,7 @@ if (isEnabled('ds-improved-ajax')) { let token = heimdall.start('json.parse'); let json; try { - json = Ember.$.parseJSON(payload); + json = $.parseJSON(payload); } catch (e) { json = payload; } diff --git a/addon/attr.js b/addon/attr.js index e2695837c53..9436a5ac818 100644 --- a/addon/attr.js +++ b/addon/attr.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import { computed } from '@ember/object'; import { deprecate } from '@ember/debug'; /** @@ -134,7 +134,7 @@ export default function attr(type, options) { options: options }; - return Ember.computed({ + return computed({ get(key) { let internalModel = this._internalModel; if (hasValue(internalModel, key)) { diff --git a/addon/index.js b/addon/index.js index db1ed47ba1f..262cb8c3247 100644 --- a/addon/index.js +++ b/addon/index.js @@ -1,3 +1,4 @@ +import EmberError from '@ember/error'; import Ember from "ember"; import { deprecate } from '@ember/debug'; @@ -8,7 +9,7 @@ import { deprecate } from '@ember/debug'; */ if (Ember.VERSION.match(/^1\.([0-9]|1[0-2])\./)) { - throw new Ember.Error("Ember Data requires at least Ember 1.13.0, but you have " + + throw new EmberError("Ember Data requires at least Ember 1.13.0, but you have " + Ember.VERSION + ". Please upgrade your version of Ember, then upgrade Ember Data."); } diff --git a/addon/serializer.js b/addon/serializer.js index 136692d1375..ebf99eaba7a 100644 --- a/addon/serializer.js +++ b/addon/serializer.js @@ -2,7 +2,7 @@ @module ember-data */ -import Ember from 'ember'; +import EmberObject from '@ember/object'; /** `DS.Serializer` is an abstract base class that you should override in your @@ -24,7 +24,7 @@ import Ember from 'ember'; @extends Ember.Object */ -export default Ember.Object.extend({ +export default EmberObject.extend({ /** The `store` property is the application's `store` that contains diff --git a/addon/serializers/embedded-records-mixin.js b/addon/serializers/embedded-records-mixin.js index e640b4d5b7e..8bd9c347e3c 100644 --- a/addon/serializers/embedded-records-mixin.js +++ b/addon/serializers/embedded-records-mixin.js @@ -1,9 +1,10 @@ -import Ember from 'ember'; +import { typeOf } from '@ember/utils'; +import { A } from '@ember/array'; +import Mixin from '@ember/object/mixin'; +import { camelize } from '@ember/string'; +import { set, get } from '@ember/object'; import { warn } from '@ember/debug'; -const { get, set } = Ember; -const { camelize } = Ember.String; - /** ## Using Embedded Records @@ -96,7 +97,7 @@ const { camelize } = Ember.String; @class EmbeddedRecordsMixin @namespace DS */ -export default Ember.Mixin.create({ +export default Mixin.create({ /** Normalize the record and recursively normalize/extract all the embedded records @@ -408,7 +409,7 @@ export default Ember.Mixin.create({ let serializedKey = this.keyForAttribute(relationship.key, 'serialize'); let hasMany = snapshot.hasMany(relationship.key); - json[serializedKey] = Ember.A(hasMany).map(function (recordSnapshot) { + json[serializedKey] = A(hasMany).map(function (recordSnapshot) { // // I'm sure I'm being utterly naive here. Propably id is a configurate property and // type too, and the modelName has to be normalized somehow. @@ -426,7 +427,7 @@ export default Ember.Mixin.create({ warn( `The embedded relationship '${serializedKey}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`, - Ember.typeOf(snapshot.hasMany(relationship.key)) !== 'undefined', + typeOf(snapshot.hasMany(relationship.key)) !== 'undefined', { id: 'ds.serializer.embedded-relationship-undefined' } ); @@ -438,7 +439,7 @@ export default Ember.Mixin.create({ */ _generateSerializedHasMany(snapshot, relationship) { let hasMany = snapshot.hasMany(relationship.key); - let manyArray = Ember.A(hasMany); + let manyArray = A(hasMany); let ret = new Array(manyArray.length); for (let i = 0; i < manyArray.length; i++) { diff --git a/addon/serializers/json-api.js b/addon/serializers/json-api.js index 19ca539bb1e..b30bba3262a 100644 --- a/addon/serializers/json-api.js +++ b/addon/serializers/json-api.js @@ -2,7 +2,9 @@ @module ember-data */ -import Ember from 'ember'; +import { typeOf, isNone } from '@ember/utils'; + +import { dasherize } from '@ember/string'; import { pluralize, singularize } from 'ember-inflector'; import { assert, deprecate, warn } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; @@ -10,8 +12,6 @@ import { DEBUG } from '@glimmer/env'; import JSONSerializer from './json'; import { normalizeModelName, isEnabled } from '../-private'; -const dasherize = Ember.String.dasherize; - /** Ember Data 2.0 Serializer: @@ -138,7 +138,7 @@ const JSONAPISerializer = JSONSerializer.extend({ */ _normalizeDocumentHelper(documentHash) { - if (Ember.typeOf(documentHash.data) === 'object') { + if (typeOf(documentHash.data) === 'object') { documentHash.data = this._normalizeResourceHelper(documentHash.data); } else if (Array.isArray(documentHash.data)) { let ret = new Array(documentHash.data.length); @@ -200,7 +200,7 @@ const JSONAPISerializer = JSONSerializer.extend({ @private */ _normalizeResourceHelper(resourceHash) { - assert(this.warnMessageForUndefinedType(), !Ember.isNone(resourceHash.type), { + assert(this.warnMessageForUndefinedType(), !isNone(resourceHash.type), { id: 'ds.serializer.type-is-undefined' }); @@ -301,7 +301,7 @@ const JSONAPISerializer = JSONSerializer.extend({ extractRelationship(relationshipHash) { - if (Ember.typeOf(relationshipHash.data) === 'object') { + if (typeOf(relationshipHash.data) === 'object') { relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data); } @@ -740,7 +740,7 @@ if (DEBUG) { JSONAPISerializer.reopen({ willMergeMixin(props) { let constructor = this.constructor; - warn(`You've defined 'extractMeta' in ${constructor.toString()} which is not used for serializers extending JSONAPISerializer. Read more at https://emberjs.com/api/data/classes/DS.JSONAPISerializer.html#toc_customizing-meta on how to customize meta when using JSON API.`, Ember.isNone(props.extractMeta) || props.extractMeta === JSONSerializer.prototype.extractMeta, { + warn(`You've defined 'extractMeta' in ${constructor.toString()} which is not used for serializers extending JSONAPISerializer. Read more at https://emberjs.com/api/data/classes/DS.JSONAPISerializer.html#toc_customizing-meta on how to customize meta when using JSON API.`, isNone(props.extractMeta) || props.extractMeta === JSONSerializer.prototype.extractMeta, { id: 'ds.serializer.json-api.extractMeta' }); warn('The JSONAPISerializer does not work with the EmbeddedRecordsMixin because the JSON API spec does not describe how to format embedded resources.', !props.isEmbeddedRecordsMixin, { diff --git a/addon/serializers/json.js b/addon/serializers/json.js index 4808cf906a3..3771326c8cd 100644 --- a/addon/serializers/json.js +++ b/addon/serializers/json.js @@ -1,4 +1,6 @@ -import Ember from 'ember'; +import { assign as emberAssign, merge } from '@ember/polyfills'; +import { isNone, typeOf } from '@ember/utils'; +import { get } from '@ember/object'; import { assert, deprecate, warn } from '@ember/debug'; import Serializer from "../serializer"; import { @@ -10,9 +12,7 @@ import { isEnabled } from '../-private'; -const get = Ember.get; -const isNone = Ember.isNone; -const assign = Ember.assign || Ember.merge; +const assign = emberAssign || merge; /** Ember Data 2.0 Serializer: @@ -458,7 +458,7 @@ const JSONSerializer = Serializer.extend({ let meta = this.extractMeta(store, primaryModelClass, payload); if (meta) { - assert('The `meta` returned from `extractMeta` has to be an object, not "' + Ember.typeOf(meta) + '".', Ember.typeOf(meta) === 'object'); + assert('The `meta` returned from `extractMeta` has to be an object, not "' + typeOf(meta) + '".', typeOf(meta) === 'object'); documentHash.meta = meta; } @@ -532,7 +532,7 @@ const JSONSerializer = Serializer.extend({ if (resourceHash) { this.normalizeUsingDeclaredMapping(modelClass, resourceHash); - if (Ember.typeOf(resourceHash.links) === 'object') { + if (typeOf(resourceHash.links) === 'object') { this.normalizeUsingDeclaredMapping(modelClass, resourceHash.links); } @@ -598,13 +598,13 @@ const JSONSerializer = Serializer.extend({ @return {Object} */ extractRelationship(relationshipModelName, relationshipHash) { - if (Ember.isNone(relationshipHash)) { return null; } + if (isNone(relationshipHash)) { return null; } /* When `relationshipHash` is an object it usually means that the relationship is polymorphic. It could however also be embedded resources that the EmbeddedRecordsMixin has be able to process. */ - if (Ember.typeOf(relationshipHash) === 'object') { + if (typeOf(relationshipHash) === 'object') { if (relationshipHash.id) { relationshipHash.id = coerceId(relationshipHash.id); } @@ -689,7 +689,7 @@ const JSONSerializer = Serializer.extend({ data = this.extractRelationship(relationshipMeta.type, relationshipHash); } } else if (relationshipMeta.kind === 'hasMany') { - if (!Ember.isNone(relationshipHash)) { + if (!isNone(relationshipHash)) { data = new Array(relationshipHash.length); for (let i = 0, l = relationshipHash.length; i < l; i++) { let item = relationshipHash[i]; diff --git a/addon/serializers/rest.js b/addon/serializers/rest.js index 88d1678e5a9..bc3cd27b1b2 100644 --- a/addon/serializers/rest.js +++ b/addon/serializers/rest.js @@ -2,15 +2,21 @@ @module ember-data */ -import Ember from 'ember'; +import { typeOf, isNone } from '@ember/utils'; + +import { makeArray } from '@ember/array'; +import { camelize } from '@ember/string'; import { singularize } from "ember-inflector"; import { assert, deprecate, warn } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; import JSONSerializer from "../serializers/json"; -import { coerceId, modelHasAttributeOrRelationshipNamedType, normalizeModelName, isEnabled } from '../-private'; - -const { camelize } = Ember.String; +import { + coerceId, + modelHasAttributeOrRelationshipNamedType, + normalizeModelName, + isEnabled +} from '../-private'; /** Normally, applications will use the `RESTSerializer` by implementing @@ -186,7 +192,7 @@ const RESTSerializer = JSONSerializer.extend({ let modelClass = store.modelFor(modelName); let serializer = store.serializerFor(modelName); - Ember.makeArray(arrayHash).forEach((hash) => { + makeArray(arrayHash).forEach((hash) => { let { data, included } = this._normalizePolymorphicRecord(store, hash, prop, modelClass, serializer); documentHash.data.push(data); if (included) { @@ -250,7 +256,7 @@ const RESTSerializer = JSONSerializer.extend({ let meta = this.extractMeta(store, primaryModelClass, payload); if (meta) { - assert('The `meta` returned from `extractMeta` has to be an object, not "' + Ember.typeOf(meta) + '".', Ember.typeOf(meta) === 'object'); + assert('The `meta` returned from `extractMeta` has to be an object, not "' + typeOf(meta) + '".', typeOf(meta) === 'object'); documentHash.meta = meta; } @@ -424,7 +430,7 @@ const RESTSerializer = JSONSerializer.extend({ var type = store.modelFor(modelName); var typeSerializer = store.serializerFor(type.modelName); - Ember.makeArray(payload[prop]).forEach(hash => { + makeArray(payload[prop]).forEach(hash => { let { data, included } = typeSerializer.normalize(type, hash, prop); documentHash.data.push(data); if (included) { @@ -773,7 +779,7 @@ const RESTSerializer = JSONSerializer.extend({ typeKey = key; } - if (Ember.isNone(belongsTo)) { + if (isNone(belongsTo)) { json[typeKey] = null; } else { if (isEnabled("ds-payload-type-hooks")) { diff --git a/addon/transforms/boolean.js b/addon/transforms/boolean.js index 51fc34d783a..4dfeb4a834c 100644 --- a/addon/transforms/boolean.js +++ b/addon/transforms/boolean.js @@ -1,8 +1,6 @@ -import Ember from 'ember'; +import { isNone } from '@ember/utils'; import Transform from './transform'; -const { isNone } = Ember; - /** The `DS.BooleanTransform` class is used to serialize and deserialize boolean attributes on Ember Data record objects. This transform is diff --git a/addon/transforms/number.js b/addon/transforms/number.js index f35dcde9be2..4bc294e9d88 100644 --- a/addon/transforms/number.js +++ b/addon/transforms/number.js @@ -1,8 +1,6 @@ -import Ember from 'ember'; +import { isEmpty as empty } from '@ember/utils'; import Transform from './transform'; -const empty = Ember.isEmpty; - function isNumber(value) { return value === value && value !== Infinity && value !== -Infinity; } diff --git a/addon/transforms/string.js b/addon/transforms/string.js index c687d3499a7..2c071006920 100644 --- a/addon/transforms/string.js +++ b/addon/transforms/string.js @@ -1,8 +1,6 @@ -import Ember from 'ember'; +import { isNone as none } from '@ember/utils'; import Transform from './transform'; -const none = Ember.isNone; - /** The `DS.StringTransform` class is used to serialize and deserialize string attributes on Ember Data record objects. This transform is diff --git a/addon/transforms/transform.js b/addon/transforms/transform.js index 524007d8519..c28586ca46c 100644 --- a/addon/transforms/transform.js +++ b/addon/transforms/transform.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import EmberObject from '@ember/object'; /** The `DS.Transform` class is used to serialize and deserialize model @@ -67,7 +67,7 @@ import Ember from 'ember'; @class Transform @namespace DS */ -export default Ember.Object.extend({ +export default EmberObject.extend({ /** When given a deserialized value from a record attribute this method must return the serialized value. diff --git a/package.json b/package.json index 7150226bca7..81d0c0ea676 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "broccoli-merge-trees": "^2.0.0", "broccoli-rollup": "^1.2.0", "chalk": "^1.1.1", - "ember-cli-babel": "^6.4.1", + "ember-cli-babel": "^6.6.0", "ember-cli-path-utils": "^1.0.0", "ember-cli-string-utils": "^1.0.0", "ember-cli-test-info": "^1.0.0", diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index 831ad6106dd..29c61429859 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -1,3 +1,4 @@ +import Application from '@ember/application'; import Ember from 'ember'; import Resolver from './resolver'; import loadInitializers from 'ember-load-initializers'; @@ -7,7 +8,7 @@ let App; Ember.MODEL_FACTORY_INJECTIONS = true; -App = Ember.Application.extend({ +App = Application.extend({ modulePrefix: config.modulePrefix, podModulePrefix: config.podModulePrefix, Resolver diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 206b248415f..00b4d2c187d 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -1,7 +1,7 @@ -import Ember from 'ember'; +import Router from '@ember/routing/router'; import config from './config/environment'; -const Router = Ember.Router.extend({ +const Router = Router.extend({ location: config.locationType, rootURL: config.rootURL }); diff --git a/tests/dummy/app/routes/application/route.js b/tests/dummy/app/routes/application/route.js index 26d9f3124ec..6c74252aa1b 100644 --- a/tests/dummy/app/routes/application/route.js +++ b/tests/dummy/app/routes/application/route.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import Route from '@ember/routing/route'; -export default Ember.Route.extend({ +export default Route.extend({ }); diff --git a/tests/dummy/app/routes/index/route.js b/tests/dummy/app/routes/index/route.js index 26d9f3124ec..6c74252aa1b 100644 --- a/tests/dummy/app/routes/index/route.js +++ b/tests/dummy/app/routes/index/route.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import Route from '@ember/routing/route'; -export default Ember.Route.extend({ +export default Route.extend({ }); diff --git a/tests/dummy/app/routes/query/controller.js b/tests/dummy/app/routes/query/controller.js index 433dfb32b26..0c416ad7362 100644 --- a/tests/dummy/app/routes/query/controller.js +++ b/tests/dummy/app/routes/query/controller.js @@ -1,8 +1,4 @@ -import Ember from 'ember'; - -const { - Controller -} = Ember; +import Controller from '@ember/controller'; export default Controller.extend({ queryParams: ['limit', 'modelName', 'included', 'eagerMaterialize', 'eagerRelationships'], diff --git a/tests/dummy/app/routes/query/route.js b/tests/dummy/app/routes/query/route.js index 552f41f2e0d..104824bce44 100644 --- a/tests/dummy/app/routes/query/route.js +++ b/tests/dummy/app/routes/query/route.js @@ -1,5 +1,5 @@ /* global window, heimdall, console */ -import Ember from 'ember'; +import Route from '@ember/routing/route'; // fallback if no-heimdall happens to be present when loading the dummy app let heimdall = self.heimdall; @@ -11,10 +11,6 @@ if (typeof heimdall !== 'object') { } -const { - Route -} = Ember; - export default Route.extend({ queryParams: { limit: { diff --git a/tests/helpers/async.js b/tests/helpers/async.js index 75f10b9960d..5a0e787af55 100644 --- a/tests/helpers/async.js +++ b/tests/helpers/async.js @@ -1,4 +1,5 @@ -import Ember from 'ember'; +import { all, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; export function wait(callback, timeout) { let done = this.async(); @@ -14,7 +15,7 @@ export function wait(callback, timeout) { let args = arguments; let result; try { - result = Ember.run(() => callback.apply(this, args)); + result = run(() => callback.apply(this, args)); } finally { done(); } @@ -23,9 +24,9 @@ export function wait(callback, timeout) { } export function asyncEqual(a, b, message) { - return Ember.RSVP.all([ - Ember.RSVP.resolve(a), - Ember.RSVP.resolve(b) + return all([ + resolve(a), + resolve(b) ]).then(this.wait((array) => { this.push(array[0] === array[1], array[0], array[1], message); })); diff --git a/tests/helpers/custom-adapter.js b/tests/helpers/custom-adapter.js index 99ca0eaa207..d5cc031a2f9 100644 --- a/tests/helpers/custom-adapter.js +++ b/tests/helpers/custom-adapter.js @@ -1,4 +1,4 @@ -import Ember from 'ember'; +import { run } from '@ember/runloop'; import DS from 'ember-data'; export default function(env, adapterDefinition) { @@ -8,5 +8,5 @@ export default function(env, adapterDefinition) { } let store = env.store; env.registry.register('adapter:-custom', adapter); - Ember.run(() => store.set('adapter', '-custom')); + run(() => store.set('adapter', '-custom')); } diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js index c3d4d1abb5d..e7f983bd14b 100644 --- a/tests/helpers/destroy-app.js +++ b/tests/helpers/destroy-app.js @@ -1,5 +1,5 @@ -import Ember from 'ember'; +import { run } from '@ember/runloop'; export default function destroyApp(application) { - Ember.run(application, 'destroy'); + run(application, 'destroy'); } diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js index 76996fd0428..0daf9c9a7e2 100644 --- a/tests/helpers/module-for-acceptance.js +++ b/tests/helpers/module-for-acceptance.js @@ -1,10 +1,8 @@ +import { Promise } from 'rsvp'; import { module } from 'qunit'; -import Ember from 'ember'; import startApp from '../helpers/start-app'; import destroyApp from '../helpers/destroy-app'; -const { RSVP: { Promise } } = Ember; - export default function(name, options = {}) { module(name, { beforeEach() { diff --git a/tests/helpers/owner.js b/tests/helpers/owner.js index f4037cda0e4..8b8e3abee97 100644 --- a/tests/helpers/owner.js +++ b/tests/helpers/owner.js @@ -1,11 +1,12 @@ +import EmberObject from '@ember/object'; import Ember from 'ember'; let Owner; if (Ember._RegistryProxyMixin && Ember._ContainerProxyMixin) { - Owner = Ember.Object.extend(Ember._RegistryProxyMixin, Ember._ContainerProxyMixin); + Owner = EmberObject.extend(Ember._RegistryProxyMixin, Ember._ContainerProxyMixin); } else { - Owner = Ember.Object.extend(); + Owner = EmberObject.extend(); } export default Owner; diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js index e098f1d5be6..37db37f585e 100644 --- a/tests/helpers/start-app.js +++ b/tests/helpers/start-app.js @@ -1,14 +1,15 @@ -import Ember from 'ember'; +import { run } from '@ember/runloop'; +import { merge } from '@ember/polyfills'; import Application from '../../app'; import config from '../../config/environment'; export default function startApp(attrs) { let application; - let attributes = Ember.merge({}, config.APP); - attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; + let attributes = merge({}, config.APP); + attributes = merge(attributes, attrs); // use defaults, but you can override; - Ember.run(() => { + run(() => { application = Application.create(attributes); application.setupForTesting(); application.injectTestHelpers(); diff --git a/tests/helpers/store.js b/tests/helpers/store.js index 10c9ca862cd..6803fd81b30 100644 --- a/tests/helpers/store.js +++ b/tests/helpers/store.js @@ -1,3 +1,4 @@ +import { dasherize } from '@ember/string'; import Ember from 'ember'; import DS from 'ember-data'; import Owner from './owner'; @@ -38,7 +39,7 @@ export default function setupStore(options) { } for (let prop in options) { - registry.register('model:' + Ember.String.dasherize(prop), options[prop]); + registry.register('model:' + dasherize(prop), options[prop]); } registry.register('service:store', DS.Store.extend({ diff --git a/tests/integration/adapter/build-url-mixin-test.js b/tests/integration/adapter/build-url-mixin-test.js index aee911e6f6f..0dc4e475c0f 100644 --- a/tests/integration/adapter/build-url-mixin-test.js +++ b/tests/integration/adapter/build-url-mixin-test.js @@ -1,14 +1,17 @@ +import { decamelize, underscore } from '@ember/string'; +import { copy } from '@ember/object/internals'; +import RSVP from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import { isEnabled } from 'ember-data/-private'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let env, store, adapter, Post, Comment, SuperUser; let passedUrl; -const { run } = Ember; module("integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter", { beforeEach() { @@ -45,13 +48,13 @@ function ajaxResponse(value) { adapter._makeRequest = function(request) { passedUrl = request.url; - return run(Ember.RSVP, 'resolve', Ember.copy(value, true)); + return run(RSVP, 'resolve', copy(value, true)); }; } else { adapter.ajax = function(url, verb, hash) { passedUrl = url; - return run(Ember.RSVP, 'resolve', Ember.copy(value, true)); + return run(RSVP, 'resolve', copy(value, true)); }; } } @@ -183,8 +186,8 @@ test('buildURL - with full URLs in links', function(assert) { test('buildURL - with camelized names', function(assert) { adapter.setProperties({ pathForType(type) { - let decamelized = Ember.String.decamelize(type); - return Ember.String.underscore(Ember.String.pluralize(decamelized)); + let decamelized = decamelize(type); + return underscore(Ember.String.pluralize(decamelized)); } }); diff --git a/tests/integration/adapter/find-all-test.js b/tests/integration/adapter/find-all-test.js index b58f70ca5c9..28ab5e1a574 100644 --- a/tests/integration/adapter/find-all-test.js +++ b/tests/integration/adapter/find-all-test.js @@ -1,13 +1,13 @@ -import {createStore} from 'dummy/tests/helpers/store'; +import { reject, resolve, defer } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; const { attr } = DS; -const { get, run } = Ember; -const { resolve, reject } = Ember.RSVP; let Person, store, allRecords, env; @@ -154,7 +154,7 @@ test("When all records for a type are requested, records that are created on the testInDebug('When all records are requested, assert the payload is not blank', (assert) => { env.registry.register('adapter:person', DS.Adapter.extend({ - findAll: () => Ember.RSVP.resolve({}) + findAll: () => resolve({}) })); assert.expectAssertion(() => { @@ -163,7 +163,7 @@ testInDebug('When all records are requested, assert the payload is not blank', ( }); test("isUpdating is true while records are fetched", function(assert) { - let findAllDeferred = Ember.RSVP.defer(); + let findAllDeferred = defer(); env.registry.register('adapter:person', DS.Adapter.extend({ findAll() { return findAllDeferred.promise; @@ -199,7 +199,7 @@ test("isUpdating is true while records are fetched", function(assert) { }); test("isUpdating is true while records are fetched in the background", function(assert) { - let findAllDeferred = Ember.RSVP.defer(); + let findAllDeferred = defer(); env.registry.register('adapter:person', DS.Adapter.extend({ findAll() { return findAllDeferred.promise; @@ -247,7 +247,7 @@ test("isUpdating is true while records are fetched in the background", function( }); test("isUpdating is false if records are not fetched in the background", function(assert) { - let findAllDeferred = Ember.RSVP.defer(); + let findAllDeferred = defer(); env.registry.register('adapter:person', DS.Adapter.extend({ findAll() { return findAllDeferred.promise; diff --git a/tests/integration/adapter/find-test.js b/tests/integration/adapter/find-test.js index 17b3225768f..4e5a98e5b14 100644 --- a/tests/integration/adapter/find-test.js +++ b/tests/integration/adapter/find-test.js @@ -1,12 +1,11 @@ +import { Promise, reject, defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { run } = Ember; const { attr } = DS; -const { reject, Promise } = Ember.RSVP; let Person, store, env; @@ -70,7 +69,7 @@ test("When a single record is requested, the adapter's find method should be cal }); test("When a single record is requested multiple times, all .findRecord() calls are resolved after the promise is resolved", function(assert) { - let deferred = Ember.RSVP.defer(); + let deferred = defer(); env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { @@ -143,7 +142,7 @@ test("When a single record is requested, and the promise is rejected, the record testInDebug('When a single record is requested, and the payload is blank', function(assert) { env.registry.register('adapter:person', DS.Adapter.extend({ - findRecord: () => Ember.RSVP.resolve({}) + findRecord: () => resolve({}) })); assert.expectAssertion(() => { @@ -154,7 +153,7 @@ testInDebug('When a single record is requested, and the payload is blank', funct testInDebug('When multiple records are requested, and the payload is blank', function(assert) { env.registry.register('adapter:person', DS.Adapter.extend({ coalesceFindRequests: true, - findMany: () => Ember.RSVP.resolve({}) + findMany: () => resolve({}) })); assert.expectAssertion(() => { diff --git a/tests/integration/adapter/json-api-adapter-test.js b/tests/integration/adapter/json-api-adapter-test.js index 313fc0ee939..acfcbf16fd4 100644 --- a/tests/integration/adapter/json-api-adapter-test.js +++ b/tests/integration/adapter/json-api-adapter-test.js @@ -1,7 +1,8 @@ +import RSVP from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import DS from 'ember-data'; @@ -10,8 +11,6 @@ import { isEnabled } from 'ember-data/-private'; let env, store, adapter; let passedUrl, passedVerb, passedHash; -const { run } = Ember; - let User, Post, Comment, Handle, GithubHandle, TwitterHandle, Company, DevelopmentShop, DesignStudio; module('integration/adapter/json-api-adapter - JSONAPIAdapter', { @@ -99,7 +98,7 @@ function ajaxResponse(responses) { passedVerb[index] = request.method; passedHash[index] = request.data ? { data: request.data } : undefined; - return run(Ember.RSVP, 'resolve', responses[index]); + return run(RSVP, 'resolve', responses[index]); }; } else { adapter.ajax = function(url, verb, hash) { @@ -109,7 +108,7 @@ function ajaxResponse(responses) { passedVerb[index] = verb; passedHash[index] = hash; - return run(Ember.RSVP, 'resolve', responses[index]); + return run(RSVP, 'resolve', responses[index]); }; } } diff --git a/tests/integration/adapter/queries-test.js b/tests/integration/adapter/queries-test.js index fcfed256fb0..d42574d137f 100644 --- a/tests/integration/adapter/queries-test.js +++ b/tests/integration/adapter/queries-test.js @@ -1,13 +1,13 @@ +import { Promise as EmberPromise, resolve } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; - let Person, env, store, adapter; module("integration/adapter/queries - Queries", { @@ -45,7 +45,7 @@ test("When a query is made, the adapter should receive a record array it can pop adapter.query = function(store, type, query, recordArray) { assert.equal(type, Person, "the query method is called with the correct type"); - return Ember.RSVP.Promise.resolve({ + return EmberPromise.resolve({ data: [ { id: 1, @@ -76,7 +76,7 @@ test("When a query is made, the adapter should receive a record array it can pop test("a query can be updated via `update()`", function(assert) { adapter.query = function() { - return Ember.RSVP.resolve({ data: [{ id: 'first', type: 'person' }] }); + return resolve({ data: [{ id: 'first', type: 'person' }] }); }; return run(() => { @@ -87,7 +87,7 @@ test("a query can be updated via `update()`", function(assert) { adapter.query = function() { assert.ok('query is called a second time'); - return Ember.RSVP.resolve({data: [{ id: 'second', type: 'person' }] }); + return resolve({data: [{ id: 'second', type: 'person' }] }); }; let updateQuery = query.update(); @@ -113,10 +113,10 @@ testInDebug("The store asserts when query is made and the adapter responses with adapter.query = function(store, type, query, recordArray) { assert.equal(type, Person, "the query method is called with the correct type"); - return Ember.RSVP.resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Peter Wagenet" } }] }); + return resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Peter Wagenet" } }] }); }; assert.expectAssertion(() => { - Ember.run(() => store.query('person', { page: 1 })); + run(() => store.query('person', { page: 1 })); }, /The response to store.query is expected to be an array but it was a single record/); }); diff --git a/tests/integration/adapter/record-persistence-test.js b/tests/integration/adapter/record-persistence-test.js index ac7047ef8c8..62da7acd16f 100644 --- a/tests/integration/adapter/record-persistence-test.js +++ b/tests/integration/adapter/record-persistence-test.js @@ -1,10 +1,11 @@ +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; +import RSVP, { resolve } from 'rsvp'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, set, run, RSVP } = Ember; const { all, hash } = RSVP; const { attr } = DS; @@ -40,7 +41,7 @@ test("When a store is committed, the adapter's `commit` method should be called assert.equal(type, Person, "the type is correct"); assert.equal(snapshot.record, tom, "the record is correct"); - return run(Ember.RSVP, 'resolve'); + return run(RSVP, 'resolve'); }; run(() => { @@ -74,7 +75,7 @@ test("When a store is committed, the adapter's `commit` method should be called assert.equal(type, Person, "the type is correct"); assert.equal(snapshot.record, tom, "the record is correct"); - return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale" } } }); + return resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale" } } }); }; return run(() => { @@ -88,7 +89,7 @@ test("After a created record has been assigned an ID, finding a record by that I let tom; env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale" } } }); + return resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale" } } }); }; return run(() => { @@ -106,7 +107,7 @@ test("when a store is committed, the adapter's `commit` method should be called assert.equal(type, Person, "the type is correct"); assert.equal(snapshot.record, tom, "the record is correct"); - return run(Ember.RSVP, 'resolve'); + return run(RSVP, 'resolve'); }; let tom; @@ -138,7 +139,7 @@ test("An adapter can notify the store that records were updated by calling `didS let tom, yehuda; env.adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve(); + return resolve(); }; run(() => { @@ -185,9 +186,9 @@ test("An adapter can notify the store that records were updated by calling `didS test("An adapter can notify the store that records were updated and provide new data by calling `didSaveRecords`.", function(assert) { env.adapter.updateRecord = function(store, type, snapshot) { if (snapshot.id === "1") { - return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } }); + return resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } }); } else if (snapshot.id === "2") { - return Ember.RSVP.resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } }); + return resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } }); } }; @@ -230,7 +231,7 @@ test("An adapter can notify the store that records were updated and provide new test("An adapter can notify the store that a record was updated by calling `didSaveRecord`.", function(assert) { env.adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve(); + return resolve(); }; run(() => { @@ -264,9 +265,9 @@ test("An adapter can notify the store that a record was updated and provide new env.adapter.updateRecord = function(store, type, snapshot) { switch (snapshot.id) { case "1": - return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } }); + return resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } }); case "2": - return Ember.RSVP.resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } }); + return resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } }); } }; @@ -309,7 +310,7 @@ test("An adapter can notify the store that a record was updated and provide new test("An adapter can notify the store that records were deleted by calling `didSaveRecords`.", function(assert) { env.adapter.deleteRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve(); + return resolve(); }; run(() => { diff --git a/tests/integration/adapter/rest-adapter-test.js b/tests/integration/adapter/rest-adapter-test.js index 403b14e4545..32ad33da4fd 100644 --- a/tests/integration/adapter/rest-adapter-test.js +++ b/tests/integration/adapter/rest-adapter-test.js @@ -1,8 +1,14 @@ +import { underscore } from '@ember/string'; +import { copy } from '@ember/object/internals'; +import RSVP, { resolve, reject } from 'rsvp'; +import $ from 'jquery'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import Pretender from "pretender"; @@ -11,8 +17,7 @@ import { isEnabled } from 'ember-data/-private'; let env, store, adapter, Post, Comment, SuperUser; let passedUrl, passedVerb, passedHash; -const { run, get } = Ember; -let originalAjax = Ember.$.ajax; +let originalAjax = $.ajax; let server; module("integration/adapter/rest_adapter - REST Adapter", { @@ -40,7 +45,7 @@ module("integration/adapter/rest_adapter - REST Adapter", { passedUrl = passedVerb = passedHash = null; }, afterEach() { - Ember.$.ajax = originalAjax; + $.ajax = originalAjax; if (server) { server.shutdown(); @@ -56,7 +61,7 @@ function ajaxResponse(value) { passedVerb = request.method; passedHash = request.data ? { data: request.data } : undefined; - return run(Ember.RSVP, 'resolve', Ember.copy(value, true)); + return run(RSVP, 'resolve', copy(value, true)); }; } else { adapter.ajax = function(url, verb, hash) { @@ -64,7 +69,7 @@ function ajaxResponse(value) { passedVerb = verb; passedHash = hash; - return run(Ember.RSVP, 'resolve', Ember.copy(value, true)); + return run(RSVP, 'resolve', copy(value, true)); }; } } @@ -1978,12 +1983,12 @@ test('groupRecordsForFindMany groups records based on their url', function(asser adapter.findRecord = function(store, type, id, snapshot) { assert.equal(id, '1'); - return Ember.RSVP.resolve({ comments: { id: 1 } }); + return resolve({ comments: { id: 1 } }); }; adapter.findMany = function(store, type, ids, snapshots) { assert.deepEqual(ids, ['2', '3']); - return Ember.RSVP.resolve({ comments: [{ id: 2 }, { id: 3 }] }); + return resolve({ comments: [{ id: 2 }, { id: 3 }] }); }; let post; @@ -2024,12 +2029,12 @@ test('groupRecordsForFindMany groups records correctly when singular URLs are en adapter.findRecord = function(store, type, id, snapshot) { assert.equal(id, '1'); - return Ember.RSVP.resolve({ comments: { id: 1 } }); + return resolve({ comments: { id: 1 } }); }; adapter.findMany = function(store, type, ids, snapshots) { assert.deepEqual(ids, ['2', '3']); - return Ember.RSVP.resolve({ comments: [{ id: 2 }, { id: 3 }] }); + return resolve({ comments: [{ id: 2 }, { id: 3 }] }); }; let post; @@ -2058,7 +2063,7 @@ test('groupRecordsForFindMany groups records correctly when singular URLs are en test('normalizeKey - to set up _ids and _id', function(assert) { env.registry.register('serializer:application', DS.RESTSerializer.extend({ keyForAttribute(attr) { - return Ember.String.underscore(attr); + return underscore(attr); }, keyForBelongsTo(belongsTo) { @@ -2066,11 +2071,11 @@ test('normalizeKey - to set up _ids and _id', function(assert) { keyForRelationship(rel, kind) { if (kind === 'belongsTo') { - let underscored = Ember.String.underscore(rel); + let underscored = underscore(rel); return underscored + '_id'; } else { let singular = Ember.String.singularize(rel); - return Ember.String.underscore(singular) + '_ids'; + return underscore(singular) + '_ids'; } } })); @@ -2162,12 +2167,12 @@ test('groupRecordsForFindMany splits up calls for large ids', function(assert) { assert.ok(true, "Found " + id); } - return Ember.RSVP.resolve({ comments: { id: id } }); + return resolve({ comments: { id: id } }); }; adapter.findMany = function(store, type, ids, snapshots) { assert.ok(false, "findMany should not be called - we expect 2 calls to find for a2000 and b2000"); - return Ember.RSVP.reject(); + return reject(); }; run(() => post.get('comments')); @@ -2209,12 +2214,12 @@ test('groupRecordsForFindMany groups calls for small ids', function(assert) { adapter.findRecord = function(store, type, id, snapshot) { assert.ok(false, "findRecord should not be called - we expect 1 call to findMany for a100 and b100"); - return Ember.RSVP.reject(); + return reject(); }; adapter.findMany = function(store, type, ids, snapshots) { assert.deepEqual(ids, [a100, b100]); - return Ember.RSVP.resolve({ comments: [{ id: a100 }, { id: b100 }] }); + return resolve({ comments: [{ id: a100 }, { id: b100 }] }); }; run(() => post.get('comments')); @@ -2234,7 +2239,7 @@ test("calls adapter.handleResponse with the jqXHR and json", function(assert) { } }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.success(data, 'ok', jqXHR); }; @@ -2260,7 +2265,7 @@ test('calls handleResponse with jqXHR, jqXHR.responseText, and requestData', fun url: "/posts/1" }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.error(jqXHR, jqXHR.responseText, 'Bad Request'); }; @@ -2285,7 +2290,7 @@ test("rejects promise if DS.AdapterError is returned from adapter.handleResponse something: 'is invalid' }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.success(data, 'ok', jqXHR); }; @@ -2294,7 +2299,7 @@ test("rejects promise if DS.AdapterError is returned from adapter.handleResponse return new DS.AdapterError(json); }; - return Ember.run(() => { + return run(() => { return store.findRecord('post', '1').catch(reason => { assert.ok(true, 'promise should be rejected'); assert.ok(reason instanceof DS.AdapterError, 'reason should be an instance of DS.AdapterError'); @@ -2309,7 +2314,7 @@ test("gracefully handles exceptions in handleResponse", function(assert) { getAllResponseHeaders() { return ''; } }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { setTimeout(function() { hash.success({}, 'ok', jqXHR); }, 1) }; @@ -2331,7 +2336,7 @@ test("gracefully handles exceptions in handleResponse where the ajax request err getAllResponseHeaders() { return ''; } }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { setTimeout(() => hash.error({}, 'Internal Server Error', jqXHR) , 1); }; @@ -2354,7 +2359,7 @@ test('treats status code 0 as an abort', function(assert) { getAllResponseHeaders() { return ''; } }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.error(jqXHR, 'error'); }; @@ -2379,7 +2384,7 @@ test('on error appends errorThrown for sanity', function(assert) { let errorThrown = new Error('nope!'); - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.error(jqXHR, jqXHR.responseText, errorThrown); }; @@ -2403,60 +2408,60 @@ if (isEnabled('ds-extended-errors')) { getAllResponseHeaders() { return ''; } }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { jqXHR.status = 401; hash.error(jqXHR, 'error'); }; - Ember.run(() => { + run(() => { store.find('post', '1').catch(reason => { assert.ok(true, 'promise should be rejected'); assert.ok(reason instanceof DS.UnauthorizedError, 'reason should be an instance of DS.UnauthorizedError'); }); }); - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { jqXHR.status = 403; hash.error(jqXHR, 'error'); }; - Ember.run(() => { + run(() => { store.find('post', '1').catch(reason => { assert.ok(true, 'promise should be rejected'); assert.ok(reason instanceof DS.ForbiddenError, 'reason should be an instance of DS.ForbiddenError'); }); }); - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { jqXHR.status = 404; hash.error(jqXHR, 'error'); }; - Ember.run(() => { + run(() => { store.find('post', '1').catch(reason => { assert.ok(true, 'promise should be rejected'); assert.ok(reason instanceof DS.NotFoundError, 'reason should be an instance of DS.NotFoundError'); }); }); - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { jqXHR.status = 409; hash.error(jqXHR, 'error'); }; - Ember.run(() => { + run(() => { store.find('post', '1').catch(reason => { assert.ok(true, 'promise should be rejected'); assert.ok(reason instanceof DS.ConflictError, 'reason should be an instance of DS.ConflictError'); }); }); - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { jqXHR.status = 500; hash.error(jqXHR, 'error'); }; - Ember.run(() => { + run(() => { store.find('post', '1').catch(reason => { assert.ok(true, 'promise should be rejected'); assert.ok(reason instanceof DS.ServerError, 'reason should be an instance of DS.ServerError'); @@ -2475,7 +2480,7 @@ test('on error wraps the error string in an DS.AdapterError object', function(as let errorThrown = 'nope!'; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.error(jqXHR, 'error', errorThrown); }; @@ -2495,7 +2500,7 @@ test('error handling includes a detailed message from the server', (assert) => { getAllResponseHeaders() { return 'Content-Type: text/plain'; } }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.error(jqXHR, 'error'); }; @@ -2517,7 +2522,7 @@ test('error handling with a very long HTML-formatted payload truncates the frien getAllResponseHeaders() { return 'Content-Type: text/html'; } }; - Ember.$.ajax = function(hash) { + $.ajax = function(hash) { hash.error(jqXHR, 'error'); }; diff --git a/tests/integration/adapter/serialize-test.js b/tests/integration/adapter/serialize-test.js index fdf961fe740..1d2a80dc3ed 100644 --- a/tests/integration/adapter/serialize-test.js +++ b/tests/integration/adapter/serialize-test.js @@ -1,12 +1,10 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { run } = Ember; - let env, store, adapter, serializer; module("integration/adapter/serialize - DS.Adapter integration test", { diff --git a/tests/integration/adapter/store-adapter-test.js b/tests/integration/adapter/store-adapter-test.js index 85326d8947a..ae6c09ecd4d 100644 --- a/tests/integration/adapter/store-adapter-test.js +++ b/tests/integration/adapter/store-adapter-test.js @@ -1,25 +1,18 @@ +import { + resolve, + hash, + Promise as EmberPromise, + reject +} from 'rsvp'; +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import DS from 'ember-data'; -/* - This is an integration test that tests the communication between a store - and its adapter. - - Typically, when a method is invoked on the store, it calls a related - method on its adapter. The adapter notifies the store that it has - completed the assigned task, either synchronously or asynchronously, - by calling a method on the store. - - These tests ensure that the proper methods get called, and, if applicable, - the given record or record array changes state appropriately. -*/ - -const { get, set, run } = Ember; let Person, Dog, env, store, adapter; function moveRecordOutOfInFlight(record) { @@ -56,7 +49,7 @@ module("integration/adapter/store-adapter - DS.Store and DS.Adapter integration test("Records loaded multiple times and retrieved in recordArray are ready to send state events", function(assert) { adapter.query = function(store, type, query, recordArray) { - return Ember.RSVP.resolve({ + return resolve({ data: [ { id: 1, @@ -78,7 +71,7 @@ test("Records loaded multiple times and retrieved in recordArray are ready to se return run(store, 'query', 'person', { q: 'bla' }).then(people => { let people2 = store.query('person', { q: 'bla2' }); - return Ember.RSVP.hash({ people: people, people2: people2 }); + return hash({ people: people, people2: people2 }); }).then(results => { assert.equal(results.people2.get('length'), 2, 'return the elements'); assert.ok(results.people2.get('isLoaded'), 'array is loaded'); @@ -110,7 +103,7 @@ test("by default, createRecords calls createRecord once per record", function(as hash['updated-at'] = "now"; count++; - return Ember.RSVP.resolve({ + return resolve({ data: { id: recordId, type: "person", @@ -127,7 +120,7 @@ test("by default, createRecords calls createRecord once per record", function(as }); let promise = run(() => { - return Ember.RSVP.hash({ + return hash({ tom: tom.save(), yehuda: yehuda.save() }); @@ -162,7 +155,7 @@ test("by default, updateRecords calls updateRecord once per record", function(as assert.equal(snapshot.record.get('isSaving'), true, "record is saving"); - return Ember.RSVP.resolve(); + return resolve(); }; run(() => { @@ -184,7 +177,7 @@ test("by default, updateRecords calls updateRecord once per record", function(as }); let promise = run(() => { - return Ember.RSVP.hash({ + return hash({ tom: store.findRecord('person', 1), yehuda: store.findRecord('person', 2) }); @@ -197,7 +190,7 @@ test("by default, updateRecords calls updateRecord once per record", function(as set(tom, "name", "Tom Dale"); set(yehuda, "name", "Yehuda Katz"); - return Ember.RSVP.hash({ + return hash({ tom: tom.save(), yehuda: yehuda.save() }); @@ -222,10 +215,10 @@ test("calling store.didSaveRecord can provide an optional hash", function(assert count++; if (count === 1) { assert.equal(snapshot.attr('name'), "Tom Dale"); - return Ember.RSVP.resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } }); + return resolve({ data: { id: 1, type: "person", attributes: { name: "Tom Dale", "updated-at": "now" } } }); } else if (count === 2) { assert.equal(snapshot.attr('name'), "Yehuda Katz"); - return Ember.RSVP.resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } }); + return resolve({ data: { id: 2, type: "person", attributes: { name: "Yehuda Katz", "updated-at": "now!" } } }); } else { assert.ok(false, "should not get here"); } @@ -250,7 +243,7 @@ test("calling store.didSaveRecord can provide an optional hash", function(assert }); let promise = run(() => { - return Ember.RSVP.hash({ + return hash({ tom: store.findRecord('person', 1), yehuda: store.findRecord('person', 2) }); @@ -263,7 +256,7 @@ test("calling store.didSaveRecord can provide an optional hash", function(assert set(tom, "name", "Tom Dale"); set(yehuda, "name", "Yehuda Katz"); - return Ember.RSVP.hash({ + return hash({ tom: tom.save(), yehuda: yehuda.save() }); @@ -297,7 +290,7 @@ test("by default, deleteRecord calls deleteRecord once per record", function(ass count++; - return Ember.RSVP.resolve(); + return resolve(); }; run(() => { @@ -319,7 +312,7 @@ test("by default, deleteRecord calls deleteRecord once per record", function(ass }); let promise = run(() => { - return Ember.RSVP.hash({ + return hash({ tom: store.findRecord('person', 1), yehuda: store.findRecord('person', 2) }); @@ -332,7 +325,7 @@ test("by default, deleteRecord calls deleteRecord once per record", function(ass tom.deleteRecord(); yehuda.deleteRecord(); - return Ember.RSVP.Promise.all([ + return EmberPromise.all([ tom.save(), yehuda.save() ]); @@ -358,7 +351,7 @@ test("by default, destroyRecord calls deleteRecord once per record without requi count++; - return Ember.RSVP.resolve(); + return resolve(); }; run(() => { @@ -380,7 +373,7 @@ test("by default, destroyRecord calls deleteRecord once per record without requi }); let promise = run(() => { - return Ember.RSVP.hash({ + return hash({ tom: store.findRecord('person', 1), yehuda: store.findRecord('person', 2) }); @@ -390,7 +383,7 @@ test("by default, destroyRecord calls deleteRecord once per record without requi let tom = records.tom; let yehuda = records.yehuda; - return Ember.RSVP.Promise.all([ + return EmberPromise.all([ tom.destroyRecord(), yehuda.destroyRecord() ]); @@ -407,7 +400,7 @@ test("if an existing model is edited then deleted, deleteRecord is called on the assert.equal(snapshot.id, 'deleted-record', "should pass correct record to deleteRecord"); assert.equal(count, 1, "should only call deleteRecord method of adapter once"); - return Ember.RSVP.resolve(); + return resolve(); }; adapter.updateRecord = function() { @@ -448,9 +441,9 @@ test("if a deleted record errors, it enters the error state", function(assert) { adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function(store, type, snapshot) { if (count++ === 0) { - return Ember.RSVP.reject(error); + return reject(error); } else { - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -490,7 +483,7 @@ test("if a created record is marked as invalid by the server, it enters an error assert.equal(type, Person, "the type is correct"); if (snapshot.attr('name').indexOf('Bro') === -1) { - return Ember.RSVP.reject(new DS.InvalidError([ + return reject(new DS.InvalidError([ { title: 'Invalid Attribute', detail: 'common... name requires a "bro"', @@ -500,7 +493,7 @@ test("if a created record is marked as invalid by the server, it enters an error } ])); } else { - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -509,7 +502,7 @@ test("if a created record is marked as invalid by the server, it enters an error }); // Wrap this in an Ember.run so that all chained async behavior is set up // before flushing any scheduled behavior. - return Ember.run(function() { + return run(function() { return yehuda.save().catch(error => { assert.equal(get(yehuda, 'isValid'), false, "the record is invalid"); assert.ok(get(yehuda, 'errors.name'), "The errors.name property exists"); @@ -537,7 +530,7 @@ test("if a created record is marked as invalid by the server, it enters an error test("allows errors on arbitrary properties on create", function(assert) { adapter.createRecord = function(store, type, snapshot) { if (snapshot.attr('name').indexOf('Bro') === -1) { - return Ember.RSVP.reject(new DS.InvalidError([ + return reject(new DS.InvalidError([ { title: "Invalid Attribute", detail: "is a generally unsavoury character", @@ -547,7 +540,7 @@ test("allows errors on arbitrary properties on create", function(assert) { } ])); } else { - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -591,7 +584,7 @@ test("if a created record is marked as invalid by the server, you can attempt th saveCount++; if (snapshot.attr('name').indexOf('Bro') === -1) { - return Ember.RSVP.reject(new DS.InvalidError([ + return reject(new DS.InvalidError([ { title: 'Invalid Attribute', detail: 'common... name requires a "bro"', @@ -601,7 +594,7 @@ test("if a created record is marked as invalid by the server, you can attempt th } ])); } else { - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -611,7 +604,7 @@ test("if a created record is marked as invalid by the server, you can attempt th // Wrap this in an Ember.run so that all chained async behavior is set up // before flushing any scheduled behavior. - return Ember.run(() => { + return run(() => { return yehuda.save().catch(reason => { assert.equal(saveCount, 1, "The record has been saved once"); assert.ok(reason.message.match("The adapter rejected the commit because it was invalid"), "It should fail due to being invalid"); @@ -642,10 +635,10 @@ test("if a created record is marked as erred by the server, it enters an error s let error = new DS.AdapterError(); adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.reject(error); + return reject(error); }; - return Ember.run(() => { + return run(() => { let person = store.createRecord('person', { id: 1, name: "John Doe" }); return person.save().catch(() => { @@ -661,7 +654,7 @@ test("if an updated record is marked as invalid by the server, it enters an erro assert.equal(type, Person, "the type is correct"); if (snapshot.attr('name').indexOf('Bro') === -1) { - return Ember.RSVP.reject(new DS.InvalidError([ + return reject(new DS.InvalidError([ { title: 'Invalid Attribute', detail: 'common... name requires a "bro"', @@ -671,7 +664,7 @@ test("if an updated record is marked as invalid by the server, it enters an erro } ])); } else { - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -689,7 +682,7 @@ test("if an updated record is marked as invalid by the server, it enters an erro return store.peekRecord('person', 1); }); - return Ember.run(() => { + return run(() => { return store.findRecord('person', 1).then(person => { assert.equal(person, yehuda, "The same object is passed through"); @@ -723,7 +716,7 @@ test("records can have errors on arbitrary properties after update", function(as adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { if (snapshot.attr('name').indexOf('Bro') === -1) { - return Ember.RSVP.reject(new DS.InvalidError([ + return reject(new DS.InvalidError([ { title: "Invalid Attribute", detail: "is a generally unsavoury character", @@ -733,7 +726,7 @@ test("records can have errors on arbitrary properties after update", function(as } ])); } else { - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -791,7 +784,7 @@ test("if an updated record is marked as invalid by the server, you can attempt t assert.equal(type, Person, "the type is correct"); saveCount++; if (snapshot.attr('name').indexOf('Bro') === -1) { - return Ember.RSVP.reject(new DS.InvalidError([ + return reject(new DS.InvalidError([ { title: 'Invalid Attribute', detail: 'common... name requires a "bro"', @@ -801,7 +794,7 @@ test("if an updated record is marked as invalid by the server, you can attempt t } ])); } else { - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -818,7 +811,7 @@ test("if an updated record is marked as invalid by the server, you can attempt t return store.peekRecord('person', 1); }); - return Ember.run(() => { + return run(() => { return store.findRecord('person', 1).then(person => { assert.equal(person, yehuda, "The same object is passed through"); @@ -856,7 +849,7 @@ test("if a updated record is marked as erred by the server, it enters an error s adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.reject(error); + return reject(error); }; let person = run(() => { @@ -887,7 +880,7 @@ test("can be created after the DS.Store", function(assert) { adapter.findRecord = function(store, type, id, snapshot) { assert.equal(type, Person, "the type is correct"); - return Ember.RSVP.resolve({ data: { id: 1, type: "person" } }); + return resolve({ data: { id: 1, type: "person" } }); }; run(() => store.findRecord('person', 1)); @@ -896,7 +889,7 @@ test("can be created after the DS.Store", function(assert) { test("the filter method can optionally take a server query as well", function(assert) { adapter.shouldBackgroundReloadRecord = () => false; adapter.query = function(store, type, query, array) { - return Ember.RSVP.resolve({ + return resolve({ data: [ { id: 1, @@ -949,7 +942,7 @@ test("relationships returned via `commit` do not trigger additional findManys", }); adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: "person", @@ -964,7 +957,7 @@ test("relationships returned via `commit` do not trigger additional findManys", }; adapter.updateRecord = function(store, type, snapshot) { - return new Ember.RSVP.Promise((resolve, reject) => { + return new EmberPromise((resolve, reject) => { env.store.push({ data: { type: 'person', @@ -1000,7 +993,7 @@ test("relationships returned via `commit` do not trigger additional findManys", return run(() => { store.findRecord('person', 1).then(person => { - return Ember.RSVP.hash({ tom: person, dog: store.findRecord('dog', 1) }); + return hash({ tom: person, dog: store.findRecord('dog', 1) }); }).then(records => { records.tom.get('dogs'); return records.dog.save(); @@ -1021,7 +1014,7 @@ test("relationships don't get reset if the links is the same", function(assert) adapter.findHasMany = function(store, snapshot, link, relationship) { assert.ok(count++ === 0, "findHasMany is only called once"); - return Ember.RSVP.resolve({ data: [{ id: 1, type: "dog", attributes: { name: "Scruffy" } }] }); + return resolve({ data: [{ id: 1, type: "dog", attributes: { name: "Scruffy" } }] }); }; run(() => { @@ -1080,7 +1073,7 @@ test("async hasMany always returns a promise", function(assert) { }); adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: "person", @@ -1112,7 +1105,7 @@ test("createRecord receives a snapshot", function(assert) { adapter.createRecord = function(store, type, snapshot) { assert.ok(snapshot instanceof DS.Snapshot, "snapshot is an instance of DS.Snapshot"); - return Ember.RSVP.resolve(); + return resolve(); }; var person; @@ -1128,7 +1121,7 @@ test("updateRecord receives a snapshot", function(assert) { adapter.updateRecord = function(store, type, snapshot) { assert.ok(snapshot instanceof DS.Snapshot, "snapshot is an instance of DS.Snapshot"); - return Ember.RSVP.resolve(); + return resolve(); }; let person; @@ -1157,7 +1150,7 @@ test("deleteRecord receives a snapshot", function(assert) { adapter.deleteRecord = function(store, type, snapshot) { assert.ok(snapshot instanceof DS.Snapshot, "snapshot is an instance of DS.Snapshot"); - return Ember.RSVP.resolve(); + return resolve(); }; let person; @@ -1186,7 +1179,7 @@ test("findRecord receives a snapshot", function(assert) { adapter.findRecord = function(store, type, id, snapshot) { assert.ok(snapshot instanceof DS.Snapshot, "snapshot is an instance of DS.Snapshot"); - return Ember.RSVP.resolve({ data: { id: 1, type: "person" } }); + return resolve({ data: { id: 1, type: "person" } }); }; return run(() => store.findRecord('person', 1)); @@ -1203,7 +1196,7 @@ test("findMany receives an array of snapshots", function(assert) { adapter.findMany = function(store, type, ids, snapshots) { assert.ok(snapshots[0] instanceof DS.Snapshot, "snapshots[0] is an instance of DS.Snapshot"); assert.ok(snapshots[1] instanceof DS.Snapshot, "snapshots[1] is an instance of DS.Snapshot"); - return Ember.RSVP.resolve({ data: [{ id: 2, type: "dog" }, { id: 3, type: "dog" }] }); + return resolve({ data: [{ id: 2, type: "dog" }, { id: 3, type: "dog" }] }); }; let person; @@ -1238,7 +1231,7 @@ test("findHasMany receives a snapshot", function(assert) { env.adapter.findHasMany = function(store, snapshot, link, relationship) { assert.ok(snapshot instanceof DS.Snapshot, "snapshot is an instance of DS.Snapshot"); - return Ember.RSVP.resolve({ data: [{ id: 2, type: "dog" }, { id: 3, type: "dog" }] }); + return resolve({ data: [{ id: 2, type: "dog" }, { id: 3, type: "dog" }] }); }; let person; @@ -1272,7 +1265,7 @@ test("findBelongsTo receives a snapshot", function(assert) { env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { assert.ok(snapshot instanceof DS.Snapshot, "snapshot is an instance of DS.Snapshot"); - return Ember.RSVP.resolve({ data: { id: 2, type: "dog" } }); + return resolve({ data: { id: 2, type: "dog" } }); }; let person; @@ -1302,7 +1295,7 @@ test("record.save should pass adapterOptions to the updateRecord method", functi env.adapter.updateRecord = function(store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); - return Ember.RSVP.resolve({ data: { id: 1, type: "person" } }); + return resolve({ data: { id: 1, type: "person" } }); }; return run(() => { @@ -1325,7 +1318,7 @@ test("record.save should pass adapterOptions to the createRecord method", functi env.adapter.createRecord = function(store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); - return Ember.RSVP.resolve({ data: { id: 1, type: "person" } }); + return resolve({ data: { id: 1, type: "person" } }); }; return run(() => { @@ -1339,7 +1332,7 @@ test("record.save should pass adapterOptions to the deleteRecord method", functi env.adapter.deleteRecord = function(store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); - return Ember.RSVP.resolve({ data: { id: 1, type: "person" } }); + return resolve({ data: { id: 1, type: "person" } }); }; run(() => { @@ -1362,7 +1355,7 @@ test("store.findRecord should pass adapterOptions to adapter.findRecord", functi env.adapter.findRecord = function(store, type, id, snapshot) { assert.deepEqual(snapshot.adapterOptions, { query: { embed: true } }); - return Ember.RSVP.resolve({ data: { id: 1, type: "person" } }); + return resolve({ data: { id: 1, type: "person" } }); }; return run(() => { @@ -1375,7 +1368,7 @@ test("store.findRecord should pass 'include' to adapter.findRecord", function(as env.adapter.findRecord = (store, type, id, snapshot) => { assert.equal(snapshot.include, 'books', 'include passed to adapter.findRecord'); - return Ember.RSVP.resolve({ data: { id: 1, type: "person" } }); + return resolve({ data: { id: 1, type: "person" } }); }; run(() => store.findRecord('person', 1, { include: 'books' })); @@ -1387,7 +1380,7 @@ test("store.findAll should pass adapterOptions to the adapter.findAll method", f env.adapter.findAll = function(store, type, sinceToken, arraySnapshot) { let adapterOptions = arraySnapshot.adapterOptions; assert.deepEqual(adapterOptions, { query: { embed: true } }); - return Ember.RSVP.resolve({ data: [{ id: 1, type: "person" }] }); + return resolve({ data: [{ id: 1, type: "person" }] }); }; return run(() => { @@ -1400,7 +1393,7 @@ test("store.findAll should pass 'include' to adapter.findAll", function(assert) env.adapter.findAll = function(store, type, sinceToken, arraySnapshot) { assert.equal(arraySnapshot.include, 'books', 'include passed to adapter.findAll'); - return Ember.RSVP.resolve({ data: [{ id: 1, type: "person" }] }); + return resolve({ data: [{ id: 1, type: "person" }] }); }; run(() => store.findAll('person', { include: 'books' })); @@ -1430,7 +1423,7 @@ test("An async hasMany relationship with links should not trigger shouldBackgrou }; }, findHasMany() { - return Ember.RSVP.resolve({ + return resolve({ comments: [ { id: 1, name: "FIRST" }, { id: 2, name: "Rails is unagi" }, diff --git a/tests/integration/application-test.js b/tests/integration/application-test.js index 665f14855c4..564097613bd 100644 --- a/tests/integration/application-test.js +++ b/tests/integration/application-test.js @@ -1,13 +1,14 @@ +import Service, { inject as service } from '@ember/service'; +import Controller from '@ember/controller'; +import Application from '@ember/application'; +import { run } from '@ember/runloop'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const run = Ember.run; -const Application = Ember.Application; -const Controller = Ember.Controller; const Store = DS.Store; const Namespace = Ember.Namespace; @@ -104,12 +105,12 @@ test("the DS namespace should be accessible", function(assert) { }); }); -if (Ember.inject && Ember.inject.service) { +if (Ember.inject && service) { module("integration/application - Using the store as a service", { beforeEach() { run(() => { app = Application.create({ - DoodleService: Ember.Service.extend({ store: Ember.inject.service() }) + DoodleService: Service.extend({ store: service() }) }); }); diff --git a/tests/integration/backwards-compat/non-dasherized-lookups-test.js b/tests/integration/backwards-compat/non-dasherized-lookups-test.js index 4741ad62c34..9cb4c3a290a 100644 --- a/tests/integration/backwards-compat/non-dasherized-lookups-test.js +++ b/tests/integration/backwards-compat/non-dasherized-lookups-test.js @@ -1,13 +1,11 @@ +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const get = Ember.get; -const { run } = Ember; - const { JSONAPIAdapter, JSONAPISerializer, diff --git a/tests/integration/client-id-generation-test.js b/tests/integration/client-id-generation-test.js index 6fe32283f51..62966f4f0d9 100644 --- a/tests/integration/client-id-generation-test.js +++ b/tests/integration/client-id-generation-test.js @@ -1,11 +1,12 @@ +import { resolve } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; let Post, Comment, Misc, env; module("integration/client_id_generation - Client-side ID Generation", { @@ -48,10 +49,10 @@ test("If an adapter implements the `generateIdForRecord` method, the store shoul env.adapter.createRecord = function(store, type, snapshot) { if (type === Comment) { assert.equal(snapshot.id, 'id-1', "Comment passed to `createRecord` has 'id-1' assigned"); - return Ember.RSVP.resolve(); + return resolve(); } else { assert.equal(snapshot.id, 'id-2', "Post passed to `createRecord` has 'id-2' assigned"); - return Ember.RSVP.resolve(); + return resolve(); } }; @@ -86,7 +87,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({ data: { id: id++, type: type.modelName } }); + return resolve({ data: { id: id++, type: type.modelName } }); }; run(() => { diff --git a/tests/integration/debug-adapter-test.js b/tests/integration/debug-adapter-test.js index b1d01a2ce72..5833c5506c8 100644 --- a/tests/integration/debug-adapter-test.js +++ b/tests/integration/debug-adapter-test.js @@ -1,16 +1,18 @@ -import Ember from 'ember'; +import { A } from '@ember/array'; +import Application from '@ember/application'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let App, store, debugAdapter; -const { get, run } = Ember; module('DS.DebugAdapter', { beforeEach() { - Ember.run(function() { - App = Ember.Application.extend({ + run(function() { + App = Application.extend({ toString() { return 'debug-app'; } }).create(); @@ -44,7 +46,7 @@ module('DS.DebugAdapter', { debugAdapter.reopen({ getModelTypes() { - return Ember.A([{ klass, name: 'post' }]); + return A([{ klass, name: 'post' }]); } }); }, @@ -86,7 +88,7 @@ test('Watching Model Types', function(assert) { test("Watching Records", function(assert) { var post, record, addedRecords, updatedRecords, removedIndex, removedCount; - Ember.run(function() { + run(function() { store.push({ data: { type: 'post', @@ -124,11 +126,11 @@ test("Watching Records", function(assert) { assert.deepEqual(record.searchKeywords, ['1', 'Clean Post']); assert.deepEqual(record.color, 'black'); - Ember.run(function() { + run(function() { post = store.findRecord('post', 1); }); - Ember.run(function() { + run(function() { post.set('title', 'Modified Post'); }); @@ -149,7 +151,7 @@ test("Watching Records", function(assert) { assert.deepEqual(record.searchKeywords, ['2', 'New Post']); assert.deepEqual(record.color, 'green'); - Ember.run(post, 'unloadRecord'); + run(post, 'unloadRecord'); assert.equal(removedIndex, 1); assert.equal(removedCount, 1); diff --git a/tests/integration/filter-test.js b/tests/integration/filter-test.js index 9670af43167..fb5a8f38d32 100644 --- a/tests/integration/filter-test.js +++ b/tests/integration/filter-test.js @@ -1,5 +1,7 @@ +import { hash, all } from 'rsvp'; +import { set, get, computed } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import { module, test } from 'qunit'; @@ -7,18 +9,12 @@ import DS from 'ember-data'; import customAdapter from 'dummy/tests/helpers/custom-adapter'; -const { - get, - set, - run -} = Ember; - let store, env, data, recordArray; const Person = DS.Model.extend({ name: DS.attr('string'), bestFriend: DS.belongsTo('person', { inverse: null, async: false }), - upperName: Ember.computed('name', function() { + upperName: computed('name', function() { return this.get('name').toUpperCase(); }).readOnly() }); @@ -235,7 +231,7 @@ test('a Record Array can update its filter', function(assert) { } }).then(recordArray => { - return Ember.RSVP.hash(asyncData).then(records => { + return hash(asyncData).then(records => { assert.contains(recordArray, records.dale); assert.contains(recordArray, records.katz); assert.without(recordArray, dickens); @@ -334,7 +330,7 @@ test('a Record Array can update its filter and notify array observers', function }); }); - return Ember.RSVP.all(asyncData).then(() => { + return all(asyncData).then(() => { assert.equal(didChangeRemoved, 1, 'removed one item from array'); didChangeRemoved = 0; diff --git a/tests/integration/injection-test.js b/tests/integration/injection-test.js index c24c4bdacbe..dfc1c82f3fd 100644 --- a/tests/integration/injection-test.js +++ b/tests/integration/injection-test.js @@ -1,3 +1,6 @@ +import EmberObject from '@ember/object'; +import { getOwner } from '@ember/application'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import DS from 'ember-data'; @@ -5,7 +8,6 @@ import { module, test } from 'qunit'; let env, hasFactoryFor, originalLookupFactory, originalOwnerLookupFactory, originalFactoryFor; let originalMODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS; -const { run } = Ember; const model = { isModel: true, @@ -19,8 +21,8 @@ module('integration/injection factoryFor enabled', { setup() { env = setupStore(); - if (Ember.getOwner) { - let owner = Ember.getOwner(env.store); + if (getOwner) { + let owner = getOwner(env.store); hasFactoryFor = !!owner.factoryFor; originalFactoryFor = owner.factoryFor; @@ -46,8 +48,8 @@ module('integration/injection factoryFor enabled', { }, teardown() { - if (Ember.getOwner) { - let owner = Ember.getOwner(env.store); + if (getOwner) { + let owner = getOwner(env.store); if (owner.factoryFor) { owner.factoryFor = originalFactoryFor; @@ -84,7 +86,7 @@ module('integration/injection eager injections', { env.registry.injection('model:foo', 'apple', 'service:apple'); env.registry.register('model:foo', DS.Model); - env.registry.register('service:apple', Ember.Object.extend({ isService: true })); + env.registry.register('service:apple', EmberObject.extend({ isService: true })); // container injection }, diff --git a/tests/integration/inverse-test.js b/tests/integration/inverse-test.js index c48bb75eb7a..d2881b9dd23 100644 --- a/tests/integration/inverse-test.js +++ b/tests/integration/inverse-test.js @@ -1,15 +1,14 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let env, store, User, Job, ReflexiveModel; const { attr, belongsTo } = DS; -const { run } = Ember; function stringify(string) { return function() { return string; }; diff --git a/tests/integration/lifecycle-hooks-test.js b/tests/integration/lifecycle-hooks-test.js index d74ae1146c6..705997b19f5 100644 --- a/tests/integration/lifecycle-hooks-test.js +++ b/tests/integration/lifecycle-hooks-test.js @@ -1,14 +1,13 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let Person, env; const { attr } = DS; -const { run } = Ember; -const { resolve } = Ember.RSVP; module("integration/lifecycle_hooks - Lifecycle Hooks", { beforeEach() { @@ -50,7 +49,7 @@ test("When the adapter acknowledges that a record has been created without a new assert.expect(3); env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve(); + return resolve(); }; let person = run(() => env.store.createRecord('person', { id: 99, name: "Yehuda Katz" })); diff --git a/tests/integration/multiple-stores-test.js b/tests/integration/multiple-stores-test.js index 4edd341eb10..bcf1fd59040 100644 --- a/tests/integration/multiple-stores-test.js +++ b/tests/integration/multiple-stores-test.js @@ -1,12 +1,11 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import { module, test } from 'qunit'; import DS from 'ember-data'; let env; let SuperVillain, HomePlanet, EvilMinion; -const { run } = Ember; module("integration/multiple_stores - Multiple Stores Tests", { setup() { diff --git a/tests/integration/peek-all-test.js b/tests/integration/peek-all-test.js index 2f836487f2c..c023ee7ee96 100644 --- a/tests/integration/peek-all-test.js +++ b/tests/integration/peek-all-test.js @@ -1,12 +1,11 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; - let Person, store, array, moreArray; module("integration/peek-all - DS.Store#peekAll()", { @@ -65,7 +64,7 @@ test("store.peekAll('person') should return all records and should update with n test("Calling store.peekAll() multiple times should update immediately inside the runloop", function(assert) { assert.expect(3); - Ember.run(() => { + run(() => { assert.equal(get(store.peekAll('person'), 'length'), 0, 'should initially be empty'); store.createRecord('person', { name: "Tomster" }); assert.equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); @@ -85,7 +84,7 @@ test("Calling store.peekAll() multiple times should update immediately inside th test("Calling store.peekAll() after creating a record should return correct data", function(assert) { assert.expect(1); - Ember.run(() => { + run(() => { store.createRecord('person', { name: "Tomster" }); assert.equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); }); diff --git a/tests/integration/polymorphic-belongs-to-test.js b/tests/integration/polymorphic-belongs-to-test.js index fc1822d96a7..e2e680f8017 100644 --- a/tests/integration/polymorphic-belongs-to-test.js +++ b/tests/integration/polymorphic-belongs-to-test.js @@ -1,12 +1,11 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; const { attr, belongsTo } = DS; -const { run } = Ember; let store; diff --git a/tests/integration/record-array-manager-test.js b/tests/integration/record-array-manager-test.js index 8e921f1d1a6..b78380b3dae 100644 --- a/tests/integration/record-array-manager-test.js +++ b/tests/integration/record-array-manager-test.js @@ -1,14 +1,14 @@ +import { A } from '@ember/array'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let store, env, manager; -const { run } = Ember; - const Person = DS.Model.extend({ name: DS.attr('string'), cars: DS.hasMany('car', { async: false }) @@ -112,20 +112,20 @@ test('destroying the store correctly cleans everything up', function(assert) { assert.equal(internalPersonModel._recordArrays.size, 3, 'expected the person to be a member of 3 recordArrays'); - Ember.run(filterd2, filterd2.destroy); + run(filterd2, filterd2.destroy); assert.equal(internalPersonModel._recordArrays.size, 2, 'expected the person to be a member of 2 recordArrays'); assert.equal(filterd2Summary.called.length, 1); assert.equal('person' in manager._liveRecordArrays, true); - Ember.run(all, all.destroy); + run(all, all.destroy); assert.equal(internalPersonModel._recordArrays.size, 1, 'expected the person to be a member of 1 recordArrays'); assert.equal(allSummary.called.length, 1); assert.equal('person' in manager._liveRecordArrays, false); - Ember.run(manager, manager.destroy); + run(manager, manager.destroy); assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of no recordArrays'); assert.equal(filterdSummary.called.length, 1); @@ -309,7 +309,7 @@ test('createRecordArray \w optional content', function(assert) { return record; } }; - let content = Ember.A([internalModel]); + let content = A([internalModel]); let recordArray = manager.createRecordArray('foo', content); assert.equal(recordArray.modelName, 'foo'); diff --git a/tests/integration/record-array-test.js b/tests/integration/record-array-test.js index e784365e397..f311d3ac9e2 100644 --- a/tests/integration/record-array-test.js +++ b/tests/integration/record-array-test.js @@ -1,13 +1,13 @@ -import {createStore} from 'dummy/tests/helpers/store'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { Promise, hash } from 'rsvp'; +import { createStore } from 'dummy/tests/helpers/store'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run, RSVP: { Promise }} = Ember; - let results; const Person = DS.Model.extend({ @@ -204,7 +204,7 @@ test('a loaded record is removed from a record array when it is deleted', functi }); return run(() => { - return Ember.RSVP.hash({ + return hash({ scumbag: store.findRecord('person', 1), tag: store.findRecord('tag', 1) }).then(records => { @@ -224,7 +224,7 @@ test('a loaded record is removed from a record array when it is deleted', functi assert.equal(get(recordArray, 'length'), 1, 'record is still in the record array until it is saved'); - Ember.run(scumbag, 'save'); + run(scumbag, 'save'); assert.equal(get(recordArray, 'length'), 0, 'record is removed from the array when it is saved'); }); @@ -352,7 +352,7 @@ test('a newly created record is removed from a record array when it is deleted', assert.equal(get(recordArray, 'length'), 1, 'precond - record array already has the first created item'); // guarantee coalescence - Ember.run(() => { + run(() => { store.createRecord('person', { name: 'p1' }); store.createRecord('person', { name: 'p2' }); store.createRecord('person', { name: 'p3' }); diff --git a/tests/integration/record-arrays/adapter-populated-record-array-test.js b/tests/integration/record-arrays/adapter-populated-record-array-test.js index 6264ed285e2..ed368e67404 100644 --- a/tests/integration/record-arrays/adapter-populated-record-array-test.js +++ b/tests/integration/record-arrays/adapter-populated-record-array-test.js @@ -1,12 +1,12 @@ -import {setupStore, createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { run } from '@ember/runloop'; +import { Promise } from 'rsvp'; +import { setupStore, createStore } from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let store; -const { run, RSVP: { Promise } } = Ember; const Person = DS.Model.extend({ name: DS.attr('string'), diff --git a/tests/integration/records/collection-save-test.js b/tests/integration/records/collection-save-test.js index 801275a7321..ebe56231995 100644 --- a/tests/integration/records/collection-save-test.js +++ b/tests/integration/records/collection-save-test.js @@ -1,12 +1,11 @@ +import { resolve, reject } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { run } = Ember; - let Post, env; module("integration/records/collection_save - Save Collection of Records", { @@ -34,7 +33,7 @@ test("Collection will resolve save on success", function(assert) { let posts = env.store.peekAll('post'); env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve({ data: { id: id++ , type: 'post' } }); + return resolve({ data: { id: id++ , type: 'post' } }); }; return run(() => { @@ -53,7 +52,7 @@ test("Collection will reject save on error", function(assert) { let posts = env.store.peekAll('post'); env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.reject(); + return reject(); }; return run(() => { @@ -76,14 +75,14 @@ test("Retry is allowed in a failure handler", function(assert) { env.adapter.createRecord = function(store, type, snapshot) { if (count++ === 0) { - return Ember.RSVP.reject(); + return reject(); } else { - return Ember.RSVP.resolve({ data: { id: id++, type: 'post' } }); + return resolve({ data: { id: id++, type: 'post' } }); } }; env.adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve({ data: { id: snapshot.id, type: 'post' } }); + return resolve({ data: { id: snapshot.id, type: 'post' } }); }; return run(() => { @@ -108,10 +107,10 @@ test("Collection will reject save on invalid", function(assert) { let posts = env.store.peekAll('post'); env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.reject({ title: 'invalid' }); + return reject({ title: 'invalid' }); }; - return Ember.run(() => { + return run(() => { return posts.save().catch(() => { assert.ok(true, 'save operation was rejected'); }); diff --git a/tests/integration/records/delete-record-test.js b/tests/integration/records/delete-record-test.js index fe3ab6b3f58..957c3ecc38f 100644 --- a/tests/integration/records/delete-record-test.js +++ b/tests/integration/records/delete-record-test.js @@ -1,16 +1,18 @@ /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|dave|cersei)" }]*/ +import { Promise as EmberPromise, all } from 'rsvp'; + +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; + import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var attr = DS.attr; var Person, env; -var run = Ember.run; -var get = Ember.get; module("integration/deletedRecord - Deleting Records", { beforeEach() { @@ -25,7 +27,7 @@ module("integration/deletedRecord - Deleting Records", { }, afterEach() { - Ember.run(function() { + run(function() { env.container.destroy(); }); } @@ -35,7 +37,7 @@ test("records should not be removed from record arrays just after deleting, but var adam, dave; env.adapter.deleteRecord = function() { - return Ember.RSVP.Promise.resolve(); + return EmberPromise.resolve(); }; var all; @@ -64,11 +66,11 @@ test("records should not be removed from record arrays just after deleting, but // pre-condition assert.equal(all.get('length'), 2, 'pre-condition: 2 records in array'); - Ember.run(adam, 'deleteRecord'); + run(adam, 'deleteRecord'); assert.equal(all.get('length'), 2, '2 records in array after deleteRecord'); - Ember.run(adam, 'save'); + run(adam, 'save'); assert.equal(all.get('length'), 1, '1 record in array after deleteRecord and save'); }); @@ -82,7 +84,7 @@ test('deleting a record that is part of a hasMany removes it from the hasMany re Group.toString = () => { return 'Group'; } env.adapter.deleteRecord = function() { - return Ember.RSVP.Promise.resolve(); + return EmberPromise.resolve(); }; env.registry.register('model:group', Group); @@ -138,7 +140,7 @@ test("records can be deleted during record array enumeration", function(assert) var adam, dave; env.adapter.deleteRecord = function() { - return Ember.RSVP.Promise.resolve(); + return EmberPromise.resolve(); }; run(function() { @@ -165,7 +167,7 @@ test("records can be deleted during record array enumeration", function(assert) // pre-condition assert.equal(all.get('length'), 2, 'expected 2 records'); - Ember.run(function() { + run(function() { all.forEach(function(record) { record.destroyRecord(); }); @@ -220,7 +222,7 @@ test("Deleting an invalid newly created record should remove it from the store", var store = env.store; env.adapter.createRecord = function() { - return Ember.RSVP.Promise.reject(new DS.InvalidError([ + return EmberPromise.reject(new DS.InvalidError([ { title: 'Invalid Attribute', detail: 'name is invalid', @@ -260,7 +262,7 @@ test("Destroying an invalid newly created record should remove it from the store }; env.adapter.createRecord = function() { - return Ember.RSVP.Promise.reject(new DS.InvalidError([ + return EmberPromise.reject(new DS.InvalidError([ { title: 'Invalid Attribute', detail: 'name is invalid', @@ -298,7 +300,7 @@ test("Will resolve destroy and save in same loop", function(assert) { env.adapter.createRecord = function() { assert.ok(true, 'save operation resolves'); - return Ember.RSVP.Promise.resolve({ + return EmberPromise.resolve({ data: { id: 123, type: 'person' @@ -318,5 +320,5 @@ test("Will resolve destroy and save in same loop", function(assert) { ]; }); - return Ember.RSVP.all(promises); + return all(promises); }); diff --git a/tests/integration/records/error-test.js b/tests/integration/records/error-test.js index a0ca3f3a941..bbe4a4bff4e 100644 --- a/tests/integration/records/error-test.js +++ b/tests/integration/records/error-test.js @@ -1,12 +1,11 @@ -import Ember from 'ember'; -import {module} from 'qunit'; +import { run } from '@ember/runloop'; +import { module } from 'qunit'; import DS from 'ember-data'; import setupStore from 'dummy/tests/helpers/store'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; var env, store, Person; var attr = DS.attr; -var run = Ember.run; function updateErrors(func) { window.expectWarning(function() { @@ -29,7 +28,7 @@ module('integration/records/error', { }, afterEach: function() { - Ember.run(function() { + run(function() { env.container.destroy(); }); } @@ -52,7 +51,7 @@ testInDebug('adding errors during root.loaded.created.invalid works', function(a return store.peekRecord('person', 'wat'); }); - Ember.run(() => { + run(() => { person.set('firstName', null); person.set('lastName', null); }); @@ -83,7 +82,7 @@ testInDebug('adding errors root.loaded.created.invalid works', function(assert) }); }); - Ember.run(() => { + run(() => { person.set('firstName', null); person.set('lastName', null); }); @@ -112,7 +111,7 @@ testInDebug('adding errors root.loaded.created.invalid works add + remove + add' }); }); - Ember.run(() => { + run(() => { person.set('firstName', null); }); @@ -143,7 +142,7 @@ testInDebug('adding errors root.loaded.created.invalid works add + (remove, add) }); }); - Ember.run(() => { + run(() => { person.set('firstName', null); }); diff --git a/tests/integration/records/load-test.js b/tests/integration/records/load-test.js index eea2c0f7ae4..605e92115c4 100644 --- a/tests/integration/records/load-test.js +++ b/tests/integration/records/load-test.js @@ -1,12 +1,12 @@ +import { reject } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; const { hasMany } = DS; -const { run } = Ember; let Post, Comment, env; @@ -28,7 +28,7 @@ module("integration/load - Loading Records", { test("When loading a record fails, the record is not left behind", function(assert) { env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.reject(); + return reject(); }; return run(() => { diff --git a/tests/integration/records/property-changes-test.js b/tests/integration/records/property-changes-test.js index a6374c7ce7d..059434d14c8 100644 --- a/tests/integration/records/property-changes-test.js +++ b/tests/integration/records/property-changes-test.js @@ -1,13 +1,13 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var env, store, Person; var attr = DS.attr; -var run = Ember.run; module('integration/records/property-changes - Property changes', { beforeEach() { @@ -23,7 +23,7 @@ module('integration/records/property-changes - Property changes', { }, afterEach() { - Ember.run(function() { + run(function() { env.container.destroy(); }); } @@ -115,7 +115,7 @@ test('Saving a record trigger observers for locally changed attributes with the var person; env.adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve({ data: { id: 'wat', type: 'person', attributes: { 'last-name': 'Katz' } } }); + return resolve({ data: { id: 'wat', type: 'person', attributes: { 'last-name': 'Katz' } } }); }; run(function() { diff --git a/tests/integration/records/relationship-changes-test.js b/tests/integration/records/relationship-changes-test.js index c0cdd002795..18575b31d57 100644 --- a/tests/integration/records/relationship-changes-test.js +++ b/tests/integration/records/relationship-changes-test.js @@ -1,10 +1,10 @@ +import { run } from '@ember/runloop'; +import EmberObject, { computed, set, get } from '@ember/object'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import DS from 'ember-data'; import { module, test } from 'qunit'; -const { run, get, set, computed } = Ember; const { attr, belongsTo, hasMany, Model } = DS; let env, store; @@ -169,7 +169,7 @@ test('Calling push with relationship triggers observers once if the relationship test('Calling push with relationship recalculates computed alias property if the relationship was empty and is added to', function(assert) { assert.expect(1); - let Obj = Ember.Object.extend({ + let Obj = EmberObject.extend({ person: null, siblings: computed.alias('person.siblings') }); @@ -224,7 +224,7 @@ test('Calling push with relationship recalculates computed alias property if the test('Calling push with relationship recalculates computed alias property to firstObject if the relationship was empty and is added to', function(assert) { assert.expect(1); - let Obj = Ember.Object.extend({ + let Obj = EmberObject.extend({ person: null, firstSibling: computed.alias('person.siblings.firstObject') }); diff --git a/tests/integration/records/reload-test.js b/tests/integration/records/reload-test.js index 76bc76b4b36..31ef546fca5 100644 --- a/tests/integration/records/reload-test.js +++ b/tests/integration/records/reload-test.js @@ -1,14 +1,14 @@ +import { resolve, reject } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -var get = Ember.get; var attr = DS.attr; var Person, env; -var run = Ember.run; module("integration/reload - Reloading Records", { beforeEach() { @@ -33,10 +33,10 @@ test("When a single record is requested, the adapter's find method should be cal env.adapter.findRecord = function(store, type, id, snapshot) { if (count === 0) { count++; - return Ember.RSVP.resolve({ data: { id: id, type: 'person', attributes: { name: "Tom Dale" } } }); + return resolve({ data: { id: id, type: 'person', attributes: { name: "Tom Dale" } } }); } else if (count === 1) { count++; - return Ember.RSVP.resolve({ data: { id: id, type: 'person', attributes: { name: "Braaaahm Dale" } } }); + return resolve({ data: { id: id, type: 'person', attributes: { name: "Braaaahm Dale" } } }); } else { assert.ok(false, "Should not get here"); } @@ -75,9 +75,9 @@ test("When a record is reloaded and fails, it can try again", function(assert) { env.adapter.findRecord = function(store, type, id, snapshot) { assert.equal(tom.get('isReloading'), true, "Tom is reloading"); if (count++ === 0) { - return Ember.RSVP.reject(); + return reject(); } else { - return Ember.RSVP.resolve({ data: { id: 1, type: 'person', attributes: { name: "Thomas Dale" } } }); + return resolve({ data: { id: 1, type: 'person', attributes: { name: "Thomas Dale" } } }); } }; @@ -147,7 +147,7 @@ test("When a record is reloaded, its async hasMany relationships still work", fu env.adapter.findRecord = function(store, type, id, snapshot) { switch (type.modelName) { case 'person': - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'person', @@ -163,7 +163,7 @@ test("When a record is reloaded, its async hasMany relationships still work", fu } }); case 'tag': - return Ember.RSVP.resolve({ data: { id: id, type: 'tag', attributes: { name: tags[id] } } }); + return resolve({ data: { id: id, type: 'tag', attributes: { name: tags[id] } } }); } }; diff --git a/tests/integration/records/rematerialize-test.js b/tests/integration/records/rematerialize-test.js index b7a71c0be8f..f507e197597 100644 --- a/tests/integration/records/rematerialize-test.js +++ b/tests/integration/records/rematerialize-test.js @@ -1,16 +1,16 @@ /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|bob|dudu)" }]*/ +import { run } from '@ember/runloop'; + import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let attr = DS.attr; let belongsTo = DS.belongsTo; let hasMany = DS.hasMany; -let run = Ember.run; let env; let Person = DS.Model.extend({ @@ -50,7 +50,7 @@ module("integration/unload - Rematerializing Unloaded Records", { }, afterEach() { - Ember.run(function() { + run(function() { env.container.destroy(); }); } diff --git a/tests/integration/records/save-test.js b/tests/integration/records/save-test.js index 397906fba22..562870048a5 100644 --- a/tests/integration/records/save-test.js +++ b/tests/integration/records/save-test.js @@ -1,12 +1,12 @@ +import { defer, reject, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var Post, env; -var run = Ember.run; module("integration/records/save - Save Record", { beforeEach() { @@ -29,7 +29,7 @@ test("Will resolve save on success", function(assert) { post = env.store.createRecord('post', { title: 'toto' }); }); - var deferred = Ember.RSVP.defer(); + var deferred = defer(); env.adapter.createRecord = function(store, type, snapshot) { return deferred.promise; }; @@ -58,7 +58,7 @@ test("Will reject save on error", function(assert) { env.adapter.createRecord = function(store, type, snapshot) { var error = new DS.InvalidError([{ title: 'not valid' }]); - return Ember.RSVP.reject(error); + return reject(error); }; run(function() { @@ -80,9 +80,9 @@ test("Retry is allowed in a failure handler", function(assert) { var error = new DS.InvalidError([{ title: 'not valid' }]); if (count++ === 0) { - return Ember.RSVP.reject(error); + return reject(error); } else { - return Ember.RSVP.resolve({ data: { id: 123, type: 'post' } }); + return resolve({ data: { id: 123, type: 'post' } }); } }; @@ -104,7 +104,7 @@ test("Repeated failed saves keeps the record in uncommited state", function(asse }); env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.reject(); + return reject(); }; run(function() { @@ -136,7 +136,7 @@ test("Repeated failed saves with invalid error marks the record as invalid", fun } ]); - return Ember.RSVP.reject(error); + return reject(error); }; run(function() { @@ -161,7 +161,7 @@ test("Repeated failed saves with invalid error without payload marks the record env.adapter.createRecord = function(store, type, snapshot) { var error = new DS.InvalidError(); - return Ember.RSVP.reject(error); + return reject(error); }; run(function() { @@ -185,7 +185,7 @@ test("Will reject save on invalid", function(assert) { env.adapter.createRecord = function(store, type, snapshot) { var error = new DS.InvalidError([{ title: 'not valid' }]); - return Ember.RSVP.reject(error); + return reject(error); }; run(function() { diff --git a/tests/integration/records/unload-test.js b/tests/integration/records/unload-test.js index c850cccf0fe..f5177752350 100644 --- a/tests/integration/records/unload-test.js +++ b/tests/integration/records/unload-test.js @@ -1,16 +1,18 @@ /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|bob|dudu)" }]*/ +import { Promise as EmberPromise } from 'rsvp'; + +import { run } from '@ember/runloop'; + import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let attr = DS.attr; let belongsTo = DS.belongsTo; let hasMany = DS.hasMany; -let run = Ember.run; let env; let Person = DS.Model.extend({ @@ -57,7 +59,7 @@ module("integration/unload - Unloading Records", { }, afterEach() { - Ember.run(function() { + run(function() { env.container.destroy(); }); } @@ -101,7 +103,7 @@ test("can unload a single record", function(assert) { assert.equal(relPayloads.get('person', 1, 'cars').data.length, 1, 'one car relationship payload is cached'); assert.equal(relPayloads.get('person', 1, 'boats').data.length, 1, 'one boat relationship payload is cached'); - Ember.run(function() { + run(function() { adam.unloadRecord(); }); @@ -162,7 +164,7 @@ test("can unload all records for a given type", function(assert) { assert.equal(relPayloads.get('car', 1, 'person').data.id, 1, 'car - person payload is loaded'); - Ember.run(function() { + run(function() { env.store.unloadAll('person'); }); @@ -171,7 +173,7 @@ test("can unload all records for a given type", function(assert) { assert.equal(env.store._internalModelsFor('person').length, 0, 'zero person internalModels loaded'); assert.equal(env.store._internalModelsFor('car').length, 1, 'one car internalModel loaded'); - Ember.run(function() { + run(function() { env.store.push({ data: { id: 1, @@ -233,7 +235,7 @@ test("can unload all records", function(assert) { assert.equal(env.store.peekAll('car').get('length'), 1, 'one car record loaded'); assert.equal(env.store._internalModelsFor('car').length, 1, 'one car internalModel loaded'); - Ember.run(function() { + run(function() { env.store.unloadAll(); }); @@ -270,7 +272,7 @@ test("removes findAllCache after unloading all records", function(assert) { assert.equal(env.store.peekAll('person').get('length'), 2, 'two person records loaded'); assert.equal(env.store._internalModelsFor('person').length, 2, 'two person internalModels loaded'); - Ember.run(function() { + run(function() { env.store.peekAll('person'); env.store.unloadAll('person'); }); @@ -305,7 +307,7 @@ test("unloading all records also updates record array from peekAll()", function( assert.equal(all.get('length'), 2); - Ember.run(function() { + run(function() { env.store.unloadAll('person'); }); assert.equal(all.get('length'), 0); @@ -693,7 +695,7 @@ test("after unloading a record, the record can be fetched again soon there after // stub findRecord env.adapter.findRecord = () => { - return Ember.RSVP.Promise.resolve({ + return EmberPromise.resolve({ data: { type: 'person', id: '1', diff --git a/tests/integration/references/belongs-to-test.js b/tests/integration/references/belongs-to-test.js index 9ba234c1ff8..fab5da5d26e 100644 --- a/tests/integration/references/belongs-to-test.js +++ b/tests/integration/references/belongs-to-test.js @@ -1,12 +1,12 @@ +import { defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import DS from 'ember-data'; -import Ember from 'ember'; import setupStore from 'dummy/tests/helpers/store'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import { isEnabled } from 'ember-data/-private'; import { module, test } from 'qunit'; -var get = Ember.get; -var run = Ember.run; var env, Family; module("integration/references/belongs-to", { @@ -248,7 +248,7 @@ test("push(promise)", function(assert) { var done = assert.async(); var push; - var deferred = Ember.RSVP.defer(); + var deferred = defer(); run(function() { var person = env.store.push({ @@ -409,7 +409,7 @@ test("load() fetches the record", function(assert) { var done = assert.async(); env.adapter.findRecord = function(store, type, id) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'family', @@ -450,7 +450,7 @@ test("load() fetches link when remoteType is link", function(assert) { env.adapter.findBelongsTo = function(store, snapshot, link) { assert.equal(link, "/families/1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'family', @@ -494,7 +494,7 @@ test("reload() - loads the record when not yet loaded", function(assert) { count++; assert.equal(count, 1); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'family', @@ -537,7 +537,7 @@ test("reload() - reloads the record when already loaded", function(assert) { count++; assert.equal(count, 1); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'family', @@ -584,7 +584,7 @@ test("reload() - uses link to reload record", function(assert) { env.adapter.findBelongsTo = function(store, snapshot, link) { assert.equal(link, "/families/1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'family', diff --git a/tests/integration/references/has-many-test.js b/tests/integration/references/has-many-test.js index 19a756c14de..3f094b647be 100755 --- a/tests/integration/references/has-many-test.js +++ b/tests/integration/references/has-many-test.js @@ -1,12 +1,12 @@ +import { defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import DS from 'ember-data'; -import Ember from 'ember'; import setupStore from 'dummy/tests/helpers/store'; import { isEnabled } from 'ember-data/-private'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import { module, test } from 'qunit'; -var get = Ember.get; -var run = Ember.run; var env, Person; module("integration/references/has-many", { @@ -431,7 +431,7 @@ test("push(promise)", function(assert) { var done = assert.async(); var push; - var deferred = Ember.RSVP.defer(); + var deferred = defer(); run(function() { var family = env.store.push({ @@ -588,7 +588,7 @@ test("load() fetches the referenced records", function(assert) { var done = assert.async(); env.adapter.findMany = function(store, type, id) { - return Ember.RSVP.resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito" } }, { id: 2, type: 'person', attributes: { name: "Michael" } }] }); + return resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito" } }, { id: 2, type: 'person', attributes: { name: "Michael" } }] }); }; var family; @@ -629,7 +629,7 @@ test("load() fetches link when remoteType is link", function(assert) { env.adapter.findHasMany = function(store, snapshot, link) { assert.equal(link, "/families/1/persons"); - return Ember.RSVP.resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito" } }, { id: 2, type: 'person', attributes: { name: "Michael" } }] }); + return resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito" } }, { id: 2, type: 'person', attributes: { name: "Michael" } }] }); }; var family; @@ -666,7 +666,7 @@ test("load() fetches link when remoteType is link but an empty set of records is env.adapter.findHasMany = function(store, snapshot, link) { assert.equal(link, "/families/1/persons"); - return Ember.RSVP.resolve({ data: [] }); + return resolve({ data: [] }); }; let family; @@ -699,7 +699,7 @@ test("load() fetches link when remoteType is link but an empty set of records is test("load() - only a single find is triggered", function(assert) { var done = assert.async(); - var deferred = Ember.RSVP.defer(); + var deferred = defer(); var count = 0; env.adapter.findMany = function(store, type, id) { @@ -753,7 +753,7 @@ test("reload()", function(assert) { var done = assert.async(); env.adapter.findMany = function(store, type, id) { - return Ember.RSVP.resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito Coreleone" } }, { id: 2, type: 'person', attributes: { name: "Michael Coreleone" } }] }); + return resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito Coreleone" } }, { id: 2, type: 'person', attributes: { name: "Michael Coreleone" } }] }); }; var family; @@ -799,9 +799,9 @@ test("reload() fetches link when remoteType is link", function(assert) { assert.equal(link, "/families/1/persons"); if (count === 1) { - return Ember.RSVP.resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito" } }, { id: 2, type: 'person', attributes: { name: "Michael" } }] }); + return resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito" } }, { id: 2, type: 'person', attributes: { name: "Michael" } }] }); } else { - return Ember.RSVP.resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito Coreleone" } }, { id: 2, type: 'person', attributes: { name: "Michael Coreleone" } }] }); + return resolve({ data: [{ id: 1, type: 'person', attributes: { name: "Vito Coreleone" } }, { id: 2, type: 'person', attributes: { name: "Michael Coreleone" } }] }); } }; diff --git a/tests/integration/references/record-test.js b/tests/integration/references/record-test.js index d29d547e093..553fd0d4116 100644 --- a/tests/integration/references/record-test.js +++ b/tests/integration/references/record-test.js @@ -1,10 +1,10 @@ +import { defer, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import DS from 'ember-data'; -import Ember from 'ember'; import setupStore from 'dummy/tests/helpers/store'; import { module, test } from 'qunit'; -var get = Ember.get; -var run = Ember.run; var env, Person; module("integration/references/record", { @@ -66,7 +66,7 @@ test("push(promise)", function(assert) { var done = assert.async(); var push; - var deferred = Ember.RSVP.defer(); + var deferred = defer(); var recordReference = env.store.getReference('person', 1); run(function() { @@ -121,7 +121,7 @@ test("load() fetches the record", function(assert) { var done = assert.async(); env.adapter.findRecord = function(store, type, id) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'person', @@ -145,7 +145,7 @@ test("load() fetches the record", function(assert) { test("load() only a single find is triggered", function(assert) { var done = assert.async(); - var deferred = Ember.RSVP.defer(); + var deferred = defer(); var count = 0; env.adapter.shouldReloadRecord = function() { return false; }; @@ -195,7 +195,7 @@ test("reload() loads the record if not yet loaded", function(assert) { count++; assert.equal(count, 1); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'person', @@ -221,7 +221,7 @@ test("reload() fetches the record", function(assert) { var done = assert.async(); env.adapter.findRecord = function(store, type, id) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'person', diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js index 33c04cc267e..7076d835bbb 100644 --- a/tests/integration/relationships/belongs-to-test.js +++ b/tests/integration/relationships/belongs-to-test.js @@ -1,12 +1,14 @@ +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import RSVP, { resolve } from 'rsvp'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run, RSVP } = Ember; const { attr, hasMany, belongsTo } = DS; const { hash } = RSVP; @@ -100,7 +102,7 @@ test("The store can materialize a non loaded monomorphic belongsTo association", env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.findRecord = function(store, type, id, snapshot) { assert.ok(true, "The adapter's find method should be called"); - return Ember.RSVP.resolve({ + return resolve({ data: { id, type: snapshot.modelName @@ -328,7 +330,7 @@ test("A serializer can materialize a belongsTo as a link that gets sent back to assert.equal(relationship.key, 'group'); assert.equal(link, "/people/1/group"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'group', @@ -385,7 +387,7 @@ test('A record with an async belongsTo relationship always returns a promise for }; env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: { id: 1, type: 'seat' } }); + return resolve({ data: { id: 1, type: 'seat' } }); }; return run(() => { @@ -436,7 +438,7 @@ test("A record with an async belongsTo relationship returning null should resolv }; env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: null }); + return resolve({ data: null }); }; return env.store.findRecord('person', '1').then(person => { @@ -862,7 +864,7 @@ test("belongsTo hasData async loaded", function(assert) { }); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -886,7 +888,7 @@ test("belongsTo hasData sync loaded", function(assert) { assert.expect(1); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -914,7 +916,7 @@ test("belongsTo hasData async not loaded", function(assert) { }); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -938,7 +940,7 @@ test("belongsTo hasData sync not loaded", function(assert) { assert.expect(1); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -1061,7 +1063,7 @@ test("Related link should be fetched when no local data is present", function(as env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { assert.equal(url, 'author', 'url is correct'); assert.ok(true, "The adapter's findBelongsTo method should be called"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'author', @@ -1103,7 +1105,7 @@ test("Local data should take precedence over related link", function(assert) { }; env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'author', @@ -1144,7 +1146,7 @@ test("New related link should take precedence over local data", function(assert) env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { assert.equal(url, 'author-new-link', 'url is correct'); assert.ok(true, "The adapter's findBelongsTo method should be called"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'author', @@ -1203,7 +1205,7 @@ test("Updated related link should take precedence over local data", function(ass env.adapter.findBelongsTo = function(store, snapshot, url, relationship) { assert.equal(url, 'author-updated-link', 'url is correct'); assert.ok(true, "The adapter's findBelongsTo method should be called"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'author', @@ -1332,7 +1334,7 @@ test("A belongsTo relationship can be reloaded using the reference if it was fet }); env.adapter.findRecord = function() { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'chapter', @@ -1346,7 +1348,7 @@ test("A belongsTo relationship can be reloaded using the reference if it was fet }; env.adapter.findBelongsTo = function() { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -1366,7 +1368,7 @@ test("A belongsTo relationship can be reloaded using the reference if it was fet assert.equal(book.get('name'), "book title"); env.adapter.findBelongsTo = function() { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -1412,7 +1414,7 @@ test("A sync belongsTo relationship can be reloaded using a reference if it was }); env.adapter.findRecord = function() { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -1452,7 +1454,7 @@ test("A belongsTo relationship can be reloaded using a reference if it was fetch }); env.adapter.findRecord = function() { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', @@ -1466,7 +1468,7 @@ test("A belongsTo relationship can be reloaded using a reference if it was fetch assert.equal(book.get('name'), "book title"); env.adapter.findRecord = function() { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'book', diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js index 9ea2db8778d..ea4e65684ba 100644 --- a/tests/integration/relationships/has-many-test.js +++ b/tests/integration/relationships/has-many-test.js @@ -1,18 +1,28 @@ /*eslint no-unused-vars: ["error", { "args": "none", "varsIgnorePattern": "(page)" }]*/ +import { A } from '@ember/array'; + +import { + resolve, + Promise as EmberPromise, + all, + reject, + hash +} from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; + import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let env, store, User, Contact, Email, Phone, Message, Post, Comment; let Book, Chapter, Page; -const { get, run } = Ember; -const { resolve } = Ember.RSVP; const { attr, hasMany, belongsTo } = DS; module("integration/relationships/has_many - Has-Many Relationships", { @@ -319,7 +329,7 @@ test("adapter.findMany only gets unique IDs even if duplicate IDs are present in assert.equal(type, Chapter, 'type passed to adapter.findMany is correct'); assert.deepEqual(ids, ['2', '3'], 'ids passed to adapter.findMany are unique'); - return Ember.RSVP.resolve({ + return resolve({ data: [ { id: 2, type: 'chapter', attributes: { title: 'Chapter One' } }, { id: 3, type: 'chapter', attributes: { title: 'Chapter Two' } } @@ -357,7 +367,7 @@ test("A serializer can materialize a hasMany as an opaque token that can be lazi assert.equal(type, Post, "find type was Post"); assert.equal(id, "1", "find id was 1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -381,7 +391,7 @@ test("A serializer can materialize a hasMany as an opaque token that can be lazi assert.equal(link, "/posts/1/comments", "findHasMany link was /posts/1/comments"); assert.equal(relationship.type, "comment", "relationship was passed correctly"); - return Ember.RSVP.resolve({ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } @@ -432,7 +442,7 @@ test("Accessing a hasMany backed by a link multiple times triggers only one requ env.adapter.findHasMany = function(store, snapshot, link, relationship) { count++; assert.equal(count, 1, "findHasMany has only been called once"); - return new Ember.RSVP.Promise((resolve, reject) => { + return new EmberPromise((resolve, reject) => { setTimeout(() => { let value = { data: [ @@ -464,7 +474,7 @@ test("Accessing a hasMany backed by a link multiple times triggers only one requ promise2 = post.get('comments'); }); - return Ember.RSVP.all([ + return all([ promise1, promise2 ]).then(() => { @@ -483,7 +493,7 @@ test("A hasMany backed by a link remains a promise after a record has been added }); env.adapter.findHasMany = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } @@ -539,11 +549,11 @@ test("A hasMany updated link should not remove new children", function(assert) { }); env.adapter.findHasMany = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: [] }); + return resolve({ data: [] }); }; env.adapter.createRecord = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -583,13 +593,13 @@ test("A hasMany updated link should not remove new children when the parent reco }); env.adapter.findHasMany = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 5, type: 'comment', attributes: { body: 'hello' } } ]}); }; env.adapter.createRecord = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -629,7 +639,7 @@ test("A hasMany relationship doesn't contain duplicate children, after the canon }); env.adapter.createRecord = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: { id: 1, type: 'post' } }); + return resolve({ data: { id: 1, type: 'post' } }); }; return run(() => { @@ -693,7 +703,7 @@ test("A hasMany relationship can be reloaded if it was fetched via a link", func assert.equal(type, Post, "find type was Post"); assert.equal(id, "1", "find id was 1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -711,7 +721,7 @@ test("A hasMany relationship can be reloaded if it was fetched via a link", func assert.equal(relationship.key, 'comments', "findHasMany relationship key was comments"); assert.equal(link, "/posts/1/comments", "findHasMany link was /posts/1/comments"); - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -729,7 +739,7 @@ test("A hasMany relationship can be reloaded if it was fetched via a link", func assert.equal(relationship.key, 'comments', "findHasMany relationship key was comments"); assert.equal(link, "/posts/1/comments", "findHasMany link was /posts/1/comments"); - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } }, { id: 3, type: 'comment', attributes: { body: "Thirds" } } @@ -752,7 +762,7 @@ test("A sync hasMany relationship can be reloaded if it was fetched via ids", fu assert.equal(type, Post, "find type was Post"); assert.equal(id, "1", "find id was 1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -791,7 +801,7 @@ test("A sync hasMany relationship can be reloaded if it was fetched via ids", fu assert.equal(comments.get('length'), 2, "comments have a length of 2"); env.adapter.findMany = function(store, type, ids, snapshots) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "FirstUpdated" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -813,7 +823,7 @@ test("A hasMany relationship can be reloaded if it was fetched via ids", functio assert.equal(type, Post, "find type was Post"); assert.equal(id, "1", "find id was 1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -827,7 +837,7 @@ test("A hasMany relationship can be reloaded if it was fetched via ids", functio }; env.adapter.findMany = function(store, type, ids, snapshots) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -841,7 +851,7 @@ test("A hasMany relationship can be reloaded if it was fetched via ids", functio assert.equal(comments.get('length'), 2, "comments have 2 length"); env.adapter.findMany = function(store, type, ids, snapshots) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "FirstUpdated" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -862,7 +872,7 @@ test("A hasMany relationship can be reloaded even if it failed at the first time }); env.adapter.findRecord = function(store, type, id) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -879,9 +889,9 @@ test("A hasMany relationship can be reloaded even if it failed at the first time env.adapter.findHasMany = function(store, record, link, relationship) { loadingCount++; if (loadingCount % 2 === 0) { - return Ember.RSVP.reject(); + return reject(); } else { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "FirstUpdated" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -917,7 +927,7 @@ test("A hasMany relationship can be directly reloaded if it was fetched via link assert.equal(type, Post, "find type was Post"); assert.equal(id, "1", "find id was 1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -933,7 +943,7 @@ test("A hasMany relationship can be directly reloaded if it was fetched via link env.adapter.findHasMany = function(store, record, link, relationship) { assert.equal(link, "/posts/1/comments", "findHasMany link was /posts/1/comments"); - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "FirstUpdated" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -958,7 +968,7 @@ test("Has many via links - Calling reload multiple times does not send a new req }); env.adapter.findRecord = function(store, type, id) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -974,7 +984,7 @@ test("Has many via links - Calling reload multiple times does not send a new req let count = 0; env.adapter.findHasMany = function(store, record, link, relationship) { count++; - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -982,7 +992,7 @@ test("Has many via links - Calling reload multiple times does not send a new req run(function() { env.store.findRecord('post', 1).then(function(post) { post.get('comments').then(function(comments) { - Ember.RSVP.all([comments.reload(), comments.reload(), comments.reload()]).then(function(comments) { + all([comments.reload(), comments.reload(), comments.reload()]).then(function(comments) { assert.equal(count, 2, "One request for the original access and only one request for the mulitple reloads"); done(); }); @@ -1000,7 +1010,7 @@ test("A hasMany relationship can be directly reloaded if it was fetched via ids" assert.equal(type, Post, "find type was Post"); assert.equal(id, "1", "find id was 1"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -1014,7 +1024,7 @@ test("A hasMany relationship can be directly reloaded if it was fetched via ids" }; env.adapter.findMany = function(store, type, ids, snapshots) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "FirstUpdated" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -1040,7 +1050,7 @@ test("Has many via ids - Calling reload multiple times does not send a new reque }); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'post', @@ -1056,7 +1066,7 @@ test("Has many via ids - Calling reload multiple times does not send a new reque let count = 0; env.adapter.findMany = function(store, type, ids, snapshots) { count++; - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "FirstUpdated" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -1065,7 +1075,7 @@ test("Has many via ids - Calling reload multiple times does not send a new reque run(function() { env.store.findRecord('post', 1).then(function(post) { post.get('comments').then(function(comments) { - Ember.RSVP.all([comments.reload(), comments.reload(), comments.reload()]).then(function(comments) { + all([comments.reload(), comments.reload(), comments.reload()]).then(function(comments) { assert.equal(count, 2, "One request for the original access and only one request for the mulitple reloads"); done(); }); @@ -1082,7 +1092,7 @@ test("PromiseArray proxies createRecord to its ManyArray once the hasMany is loa }); env.adapter.findHasMany = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -1126,7 +1136,7 @@ test("PromiseArray proxies evented methods to its ManyArray", function(assert) { }); env.adapter.findHasMany = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); @@ -1193,12 +1203,12 @@ test("An updated `links` value should invalidate a relationship cache", function assert.equal(relationship.type, "comment", "relationship was passed correctly"); if (link === '/first') { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); } else if (link === '/second') { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 3, type: 'comment', attributes: { body: "Third" } }, { id: 4, type: 'comment', attributes: { body: "Fourth" } }, { id: 5, type: 'comment', attributes: { body: "Fifth" } } @@ -1303,9 +1313,9 @@ test("When a polymorphic hasMany relationship is accessed, the store can call mu env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.findRecord = function(store, type, id, snapshot) { if (type === Post) { - return Ember.RSVP.resolve({ data: { id: 1, type: 'post' } }); + return resolve({ data: { id: 1, type: 'post' } }); } else if (type === Comment) { - return Ember.RSVP.resolve({ data: { id: 3, type: 'comment' } }); + return resolve({ data: { id: 3, type: 'comment' } }); } }; @@ -1564,7 +1574,7 @@ testInDebug("Only records of the same type can be added to a monomorphic hasMany }); run(function() { - Ember.RSVP.all([ + all([ env.store.findRecord('post', 1), env.store.findRecord('post', 2) ]).then(function(records) { @@ -1614,7 +1624,7 @@ testInDebug("Only records of the same base modelClass can be added to a polymorp let asyncRecords; run(function() { - asyncRecords = Ember.RSVP.hash({ + asyncRecords = hash({ user: env.store.findRecord('user', 1), anotherUser: env.store.findRecord('user', 2), post: env.store.findRecord('post', 1), @@ -1623,7 +1633,7 @@ testInDebug("Only records of the same base modelClass can be added to a polymorp asyncRecords.then(function(records) { records.messages = records.user.get('messages'); - return Ember.RSVP.hash(records); + return hash(records); }).then(function(records) { records.messages.pushObject(records.post); records.messages.pushObject(records.comment); @@ -1661,14 +1671,14 @@ test("A record can be removed from a polymorphic association", function(assert) let asyncRecords; run(function() { - asyncRecords = Ember.RSVP.hash({ + asyncRecords = hash({ user: env.store.findRecord('user', 1), comment: env.store.findRecord('comment', 3) }); asyncRecords.then(function(records) { records.messages = records.user.get('messages'); - return Ember.RSVP.hash(records); + return hash(records); }).then(function(records) { assert.equal(records.messages.get('length'), 1, "The user has 1 message"); @@ -1789,7 +1799,7 @@ test("When a record is saved, its unsaved hasMany records should be kept", funct let post, comment; env.adapter.createRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve({ data: { id: 1, type: snapshot.modelName } }); + return resolve({ data: { id: 1, type: snapshot.modelName } }); }; return run(() => { @@ -1814,7 +1824,7 @@ test("dual non-async HM <-> BT", function(assert) { env.adapter.createRecord = function(store, type, snapshot) { let serialized = snapshot.record.serialize(); serialized.data.id = 2; - return Ember.RSVP.resolve(serialized); + return resolve(serialized); }; let post, firstComment; @@ -2482,7 +2492,7 @@ test("Relationship.clear removes all records correctly", function(assert) { env.store.peekAll('comment').mapBy('post'); post._internalModel._relationships.get('comments').clear(); - let comments = Ember.A(env.store.peekAll('comment')); + let comments = A(env.store.peekAll('comment')); assert.deepEqual(comments.mapBy('post'), [null, null, null]); }); }); @@ -2577,13 +2587,13 @@ test("adding and removing records from hasMany relationship #2666", function(ass let commentId = 4; env.registry.register('adapter:comment', DS.RESTAdapter.extend({ deleteRecord(record) { - return Ember.RSVP.resolve(); + return resolve(); }, updateRecord(record) { - return Ember.RSVP.resolve(); + return resolve(); }, createRecord() { - return Ember.RSVP.resolve({ comments: { id: commentId++ }}); + return resolve({ comments: { id: commentId++ }}); } })); @@ -2655,7 +2665,7 @@ test("hasMany hasData async loaded", function(assert) { }); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'chapter', @@ -2681,7 +2691,7 @@ test("hasMany hasData sync loaded", function(assert) { assert.expect(1); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'chapter', @@ -2711,7 +2721,7 @@ test("hasMany hasData async not loaded", function(assert) { }); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'chapter', @@ -2737,7 +2747,7 @@ test("hasMany hasData sync not loaded", function(assert) { assert.expect(1); env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'chapter', @@ -2986,7 +2996,7 @@ test("Related link should be fetched when no local data is present", function(as env.adapter.findHasMany = function(store, snapshot, url, relationship) { assert.equal(url, 'comments', 'url is correct'); assert.ok(true, "The adapter's findHasMany method should be called"); - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: 'This is comment' } } ]}); }; @@ -3024,7 +3034,7 @@ test("Local data should take precedence over related link", function(assert) { }; env.adapter.findRecord = function(store, type, id, snapshot) { - return Ember.RSVP.resolve({ data: { id: 1, type: 'comment', attributes: { body: 'This is comment' } } }); + return resolve({ data: { id: 1, type: 'comment', attributes: { body: 'This is comment' } } }); }; return run(() => { @@ -3061,7 +3071,7 @@ test("Updated related link should take precedence over local data", function(ass env.adapter.findHasMany = function(store, snapshot, url, relationship) { assert.equal(url, 'comments-updated-link', 'url is correct'); assert.ok(true, "The adapter's findHasMany method should be called"); - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: 'This is comment' } } ]}); }; @@ -3116,7 +3126,7 @@ test("PromiseArray proxies createRecord to its ManyArray before the hasMany is l }); env.adapter.findHasMany = function(store, record, link, relationship) { - return Ember.RSVP.resolve({ data: [ + return resolve({ data: [ { id: 1, type: 'comment', attributes: { body: "First" } }, { id: 2, type: 'comment', attributes: { body: "Second" } } ]}); diff --git a/tests/integration/relationships/inverse-relationships-test.js b/tests/integration/relationships/inverse-relationships-test.js index 99f7f217224..cb14af74e22 100644 --- a/tests/integration/relationships/inverse-relationships-test.js +++ b/tests/integration/relationships/inverse-relationships-test.js @@ -1,14 +1,13 @@ -import {createStore} from 'dummy/tests/helpers/store'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var Post, Comment, Message, User; -var run = Ember.run; module('integration/relationships/inverse_relationships - Inverse Relationships'); diff --git a/tests/integration/relationships/many-to-many-test.js b/tests/integration/relationships/many-to-many-test.js index ae3016fe73f..82f0746466e 100644 --- a/tests/integration/relationships/many-to-many-test.js +++ b/tests/integration/relationships/many-to-many-test.js @@ -1,13 +1,15 @@ /*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(ada)" }]*/ +import { resolve, Promise as EmberPromise } from 'rsvp'; + +import { run } from '@ember/runloop'; + import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { run } = Ember; const { attr, hasMany } = DS; let Account, Topic, User, store, env; @@ -35,7 +37,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', topic: Topic, account: Account, adapter: DS.Adapter.extend({ - deleteRecord: () => Ember.RSVP.resolve() + deleteRecord: () => resolve() }) }); @@ -434,7 +436,7 @@ test("Rollbacking attributes for a deleted record that has a ManyToMany relation assert.equal(fetchedTopics.get('length'), 1, 'Topic got rollbacked into the user'); }); - return Ember.RSVP.Promise.all([ + return EmberPromise.all([ users, topics ]); @@ -511,7 +513,7 @@ test("Rollbacking attributes for a created record that has a ManyToMany relation assert.equal(fetchedTopics.objectAt(0), null, "Topic can't be fetched"); }); - return Ember.RSVP.Promise.all([ + return EmberPromise.all([ users, topics ]); diff --git a/tests/integration/relationships/one-to-many-test.js b/tests/integration/relationships/one-to-many-test.js index 59a5f5feb7e..7477cea1d63 100644 --- a/tests/integration/relationships/one-to-many-test.js +++ b/tests/integration/relationships/one-to-many-test.js @@ -1,13 +1,13 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var env, store, User, Message, Account; -var get = Ember.get; -var run = Ember.run; var attr = DS.attr; var hasMany = DS.hasMany; @@ -36,7 +36,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', { message: Message, account: Account, adapter: DS.Adapter.extend({ - deleteRecord: () => Ember.RSVP.resolve() + deleteRecord: () => resolve() }) }); diff --git a/tests/integration/relationships/one-to-one-test.js b/tests/integration/relationships/one-to-one-test.js index a4b9038aed1..c65f848b149 100644 --- a/tests/integration/relationships/one-to-one-test.js +++ b/tests/integration/relationships/one-to-one-test.js @@ -1,13 +1,13 @@ +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var env, store, User, Job; -var run = Ember.run; var attr = DS.attr; var belongsTo = DS.belongsTo; @@ -29,7 +29,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', { user: User, job: Job, adapter: DS.Adapter.extend({ - deleteRecord: () => Ember.RSVP.resolve() + deleteRecord: () => resolve() }) }); @@ -532,7 +532,7 @@ testInDebug("Setting a BelongsTo to a promise that didn't come from a relationsh assert.expectAssertion(function() { run(function() { - stanley.set('bestFriend', Ember.RSVP.resolve(igor)); + stanley.set('bestFriend', resolve(igor)); }); }, /You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo or hasMany relationship to the get call./); }); @@ -588,10 +588,10 @@ test("Setting a BelongsTo to a promise multiple times is resistant to race condi env.adapter.findRecord = function(store, type, id, snapshot) { if (id === '5') { - return Ember.RSVP.resolve({ data: { id: 5, type: 'user', attributes: { name: "Igor's friend" } } }); + return resolve({ data: { id: 5, type: 'user', attributes: { name: "Igor's friend" } } }); } else if (id === '2') { let done = assert.async(); - return new Ember.RSVP.Promise(function(resolve, reject) { + return new EmberPromise(function(resolve, reject) { setTimeout(function() { done(); resolve({ data: { id: 2, type: 'user', attributes: { name: "Stanley's friend" } } }); diff --git a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js index 9439b60d168..1b70a29f817 100644 --- a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js +++ b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js @@ -1,13 +1,14 @@ +import Mixin from '@ember/object/mixin'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var env, store, User, Message, Video, NotMessage; -var run = Ember.run; var attr = DS.attr; var belongsTo = DS.belongsTo; @@ -19,7 +20,7 @@ module('integration/relationships/polymorphic_mixins_belongs_to_test - Polymorph bestMessage: belongsTo('message', { async: true, polymorphic: true }) }); - Message = Ember.Mixin.create({ + Message = Mixin.create({ title: attr('string'), user: belongsTo('user', { async: true }) }); diff --git a/tests/integration/relationships/polymorphic-mixins-has-many-test.js b/tests/integration/relationships/polymorphic-mixins-has-many-test.js index 9141b088522..a6f6268dfd4 100644 --- a/tests/integration/relationships/polymorphic-mixins-has-many-test.js +++ b/tests/integration/relationships/polymorphic-mixins-has-many-test.js @@ -1,13 +1,14 @@ +import Mixin from '@ember/object/mixin'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var env, store, User, Message, NotMessage, Video; -var run = Ember.run; var attr = DS.attr; var hasMany = DS.hasMany; @@ -20,7 +21,7 @@ module('integration/relationships/polymorphic_mixins_has_many_test - Polymorphic messages: hasMany('message', { async: true, polymorphic: true }) }); - Message = Ember.Mixin.create({ + Message = Mixin.create({ title: attr('string'), user: belongsTo('user', { async: true }) }); diff --git a/tests/integration/serializers/embedded-records-mixin-test.js b/tests/integration/serializers/embedded-records-mixin-test.js index 78ca55ae5ca..fc6a8b3bc26 100644 --- a/tests/integration/serializers/embedded-records-mixin-test.js +++ b/tests/integration/serializers/embedded-records-mixin-test.js @@ -1,15 +1,15 @@ +import { w } from '@ember/string'; +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -var get = Ember.get; var HomePlanet, SuperVillain, CommanderVillain, NormalMinion, EvilMinion, YellowMinion, RedMinion, SecretLab, SecretWeapon, BatCave, Comment, league, superVillain, commanderVillain, evilMinion, yellowMinion, redMinion, secretWeapon, homePlanet, secretLab, env; -var run = Ember.run; var LightSaber; module("integration/embedded_records_mixin - EmbeddedRecordsMixin", { @@ -2117,7 +2117,7 @@ test("serializing relationships with an embedded and without calls super when no var payloadKey = this.keyForRelationship ? this.keyForRelationship(key, "hasMany") : key; var relationshipType = snapshot.type.determineRelationshipType(relationship); // "manyToOne" not supported in DS.ActiveModelSerializer.prototype.serializeHasMany - var relationshipTypes = Ember.String.w('manyToNone manyToMany manyToOne'); + var relationshipTypes = w('manyToNone manyToMany manyToOne'); if (relationshipTypes.indexOf(relationshipType) > -1) { json[payloadKey] = snapshot.hasMany(key, { ids: true }); } diff --git a/tests/integration/serializers/json-api-serializer-test.js b/tests/integration/serializers/json-api-serializer-test.js index a597ca058c8..559a46e5d03 100644 --- a/tests/integration/serializers/json-api-serializer-test.js +++ b/tests/integration/serializers/json-api-serializer-test.js @@ -1,8 +1,9 @@ +import { run } from '@ember/runloop'; +import { get } from '@ember/object'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import { isEnabled } from 'ember-data/-private'; @@ -10,9 +11,6 @@ import DS from 'ember-data'; var env, store, serializer; -var get = Ember.get; -var run = Ember.run; - var User, Handle, GithubHandle, TwitterHandle, Company, Project; module('integration/serializers/json-api-serializer - JSONAPISerializer', { diff --git a/tests/integration/serializers/json-serializer-test.js b/tests/integration/serializers/json-serializer-test.js index 8fae94bf3f9..1c8172d1a92 100644 --- a/tests/integration/serializers/json-serializer-test.js +++ b/tests/integration/serializers/json-serializer-test.js @@ -1,14 +1,14 @@ +import { underscore } from '@ember/string'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import { isEnabled } from 'ember-data/-private'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var Post, post, Comment, comment, Favorite, favorite, env, serializer; -var run = Ember.run; module("integration/serializer/json - JSONSerializer", { beforeEach() { @@ -400,7 +400,7 @@ test('Serializer should map `attrs` attributes directly when keyForAttribute als post: Post }); env.registry.register("serializer:post", DS.JSONSerializer.extend({ - keyForAttribute: Ember.String.underscore, + keyForAttribute: underscore, attrs: { authorName: 'author_name_key' } diff --git a/tests/integration/serializers/rest-serializer-test.js b/tests/integration/serializers/rest-serializer-test.js index b9b2cb6b60e..45ba54c2fc9 100644 --- a/tests/integration/serializers/rest-serializer-test.js +++ b/tests/integration/serializers/rest-serializer-test.js @@ -1,14 +1,15 @@ +import { camelize, decamelize, dasherize } from '@ember/string'; +import { run, bind } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import { isEnabled } from 'ember-data/-private'; import DS from 'ember-data'; var HomePlanet, league, SuperVillain, EvilMinion, YellowMinion, DoomsdayDevice, Comment, Basket, Container, env; -var run = Ember.run; module("integration/serializer/rest - RESTSerializer", { beforeEach() { @@ -103,7 +104,7 @@ test("normalizeResponse with custom modelNameFromPayloadKey", function(assert) { assert.expect(1); env.restSerializer.modelNameFromPayloadKey = function(root) { - var camelized = Ember.String.camelize(root); + var camelized = camelize(root); return Ember.String.singularize(camelized); }; env.registry.register('serializer:home-planet', DS.JSONSerializer); @@ -214,7 +215,7 @@ testInDebug("normalizeResponse warning with custom modelNameFromPayloadKey", fun home_planet: { id: "1", name: "Umber", superVillains: [1] } }; - assert.expectWarning(Ember.run.bind(null, function() { + assert.expectWarning(bind(null, function() { run(function() { env.restSerializer.normalizeResponse(env.store, HomePlanet, jsonHash, '1', 'findRecord'); }); @@ -256,7 +257,7 @@ testInDebug("normalizeResponse warning with custom modelNameFromPayloadKey", fun // should not warn if a model is found. env.restSerializer.modelNameFromPayloadKey = function(root) { - return Ember.String.camelize(Ember.String.singularize(root)); + return camelize(Ember.String.singularize(root)); }; jsonHash = { @@ -490,7 +491,7 @@ test('normalize should allow for different levels of normalization', function(as superVillain: 'is_super_villain' }, keyForAttribute(attr) { - return Ember.String.decamelize(attr); + return decamelize(attr); } })); @@ -512,7 +513,7 @@ test('normalize should allow for different levels of normalization - attributes' name: 'full_name' }, keyForAttribute(attr) { - return Ember.String.decamelize(attr); + return decamelize(attr); } })); @@ -655,7 +656,7 @@ test('serializeIntoHash uses payloadKeyFromModelName to normalize the payload ro var json = {}; env.registry.register('serializer:home-planet', DS.RESTSerializer.extend({ payloadKeyFromModelName(modelName) { - return Ember.String.dasherize(modelName); + return dasherize(modelName); } })); diff --git a/tests/integration/setup-container-test.js b/tests/integration/setup-container-test.js index eaaf937e554..68286a4caa5 100644 --- a/tests/integration/setup-container-test.js +++ b/tests/integration/setup-container-test.js @@ -1,10 +1,11 @@ -import Ember from 'ember'; +import Application from '@ember/application'; +import { run } from '@ember/runloop'; +import EmberObject from '@ember/object'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { run, Object: EmberObject } = Ember; const { Store, _setupContainer: setupContainer } = DS; let container, registry, application; @@ -16,7 +17,7 @@ let container, registry, application; module("integration/setup-container - Setting up a container", { beforeEach() { - application = run(() => Ember.Application.create()); + application = run(() => Application.create()); container = application.__container__; registry = application.__registry__; diff --git a/tests/integration/snapshot-test.js b/tests/integration/snapshot-test.js index 992907ef007..b92963cf6e3 100644 --- a/tests/integration/snapshot-test.js +++ b/tests/integration/snapshot-test.js @@ -1,11 +1,11 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { run } = Ember; let env, Post, Comment; module("integration/snapshot - DS.Snapshot", { @@ -372,7 +372,7 @@ test("snapshot.belongsTo() returns a snapshot if relationship link has been fetc assert.expect(2); env.adapter.findBelongsTo = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: { id: 1, type: 'post', attributes: { title: 'Hello World' } } }); + return resolve({ data: { id: 1, type: 'post', attributes: { title: 'Hello World' } } }); }; return run(() => { @@ -804,7 +804,7 @@ test("snapshot.hasMany() returns array of snapshots if relationship link has bee assert.expect(2); env.adapter.findHasMany = function(store, snapshot, link, relationship) { - return Ember.RSVP.resolve({ data: [{ id: 2, type: 'comment', attributes: { body: 'This is comment' } }]}); + return resolve({ data: [{ id: 2, type: 'comment', attributes: { body: 'This is comment' } }]}); }; return run(() => { diff --git a/tests/integration/store-test.js b/tests/integration/store-test.js index 03abfe1b4b6..e3772017b6d 100644 --- a/tests/integration/store-test.js +++ b/tests/integration/store-test.js @@ -1,8 +1,14 @@ +import { copy } from '@ember/object/internals'; +import { assert } from '@ember/debug'; +import RSVP, { + Promise as EmberPromise, + resolve +} from 'rsvp'; +import { run, next } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; import { isEnabled } from 'ember-data/-private'; @@ -20,7 +26,6 @@ Person.reopenClass({ } }); -const { run } = Ember; const Car = DS.Model.extend({ make: DS.attr('string'), model: DS.attr('string'), @@ -76,8 +81,8 @@ test("destroying record during find doesn't cause error", function(assert) { let TestAdapter = DS.Adapter.extend({ findRecord(store, type, id, snapshot) { - return new Ember.RSVP.Promise((resolve, reject) => { - Ember.run.next(() => { + return new EmberPromise((resolve, reject) => { + next(() => { store.unloadAll(type.modelName); reject(); }); @@ -100,7 +105,7 @@ test("find calls do not resolve when the store is destroyed", function(assert) { let TestAdapter = DS.Adapter.extend({ findRecord(store, type, id, snapshot) { store.destroy(); - Ember.RSVP.resolve(null); + resolve(null); } }); @@ -111,7 +116,7 @@ test("find calls do not resolve when the store is destroyed", function(assert) { let id = 1; store.push = function() { - Ember.assert("The test should have destroyed the store by now", store.get("isDestroyed")); + assert("The test should have destroyed the store by now", store.get("isDestroyed")); throw new Error("We shouldn't be pushing data into the store when it is destroyed"); }; @@ -197,7 +202,7 @@ test("destroying the store correctly cleans everything up", function(assert) { assert.equal(car.get('person'), person, "expected car's person to be the correct person"); assert.equal(person.get('cars.firstObject'), car, " expected persons cars's firstRecord to be the correct car"); - Ember.run(store, 'destroy'); + run(store, 'destroy'); assert.equal(personWillDestroy.called.length, 1, 'expected person to have recieved willDestroy once'); assert.equal(carWillDestroy.called.length, 1, 'expected car to recieve willDestroy once'); @@ -209,11 +214,11 @@ test("destroying the store correctly cleans everything up", function(assert) { function ajaxResponse(value) { if (isEnabled('ds-improved-ajax')) { env.adapter._makeRequest = function() { - return run(Ember.RSVP, 'resolve', Ember.copy(value, true)); + return run(RSVP, 'resolve', copy(value, true)); }; } else { env.adapter.ajax = function(url, verb, hash) { - return run(Ember.RSVP, 'resolve', Ember.copy(value, true)); + return run(RSVP, 'resolve', copy(value, true)); }; } } diff --git a/tests/integration/store/json-api-validation-test.js b/tests/integration/store/json-api-validation-test.js index b4015274c5c..47300f88518 100644 --- a/tests/integration/store/json-api-validation-test.js +++ b/tests/integration/store/json-api-validation-test.js @@ -1,11 +1,11 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import QUnit, { module } from 'qunit'; import DS from 'ember-data'; var Person, store, env; -var run = Ember.run; function payloadError(payload, expectedError) { env.registry.register('serializer:person', DS.Serializer.extend({ @@ -15,7 +15,7 @@ function payloadError(payload, expectedError) { })); env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve(payload); + return resolve(payload); } })); this.throws(function () { @@ -58,7 +58,7 @@ testInDebug("when normalizeResponse returns undefined (or doesn't return), throw env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({ data: {} }); + return resolve({ data: {} }); } })); @@ -77,7 +77,7 @@ testInDebug("when normalizeResponse returns null, throws an error", function(ass env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({ data: {} }); + return resolve({ data: {} }); } })); @@ -97,7 +97,7 @@ testInDebug("when normalizeResponse returns an empty object, throws an error", f env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({ data: {} }); + return resolve({ data: {} }); } })); @@ -121,7 +121,7 @@ testInDebug("when normalizeResponse returns a document with both data and errors env.registry.register('adapter:person', DS.Adapter.extend({ findRecord() { - return Ember.RSVP.resolve({ data: {} }); + return resolve({ data: {} }); } })); diff --git a/tests/integration/store/query-record-test.js b/tests/integration/store/query-record-test.js index a712c6ef5c3..b83aa9bfa69 100644 --- a/tests/integration/store/query-record-test.js +++ b/tests/integration/store/query-record-test.js @@ -1,13 +1,13 @@ +import { resolve, reject } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; var Person, store, env; -var run = Ember.run; module("integration/store/query-record - Query one record with a query hash", { beforeEach() { @@ -47,7 +47,7 @@ test("When a record is requested, the adapter's queryRecord method should be cal env.registry.register('adapter:person', DS.Adapter.extend({ queryRecord(store, type, query) { assert.equal(type, Person, "the query method is called with the correct type"); - return Ember.RSVP.resolve({ data: { id: 1, type: 'person', attributes: { name: "Peter Wagenet" } } }); + return resolve({ data: { id: 1, type: 'person', attributes: { name: "Peter Wagenet" } } }); } })); @@ -59,7 +59,7 @@ test("When a record is requested, the adapter's queryRecord method should be cal test("When a record is requested, and the promise is rejected, .queryRecord() is rejected.", function(assert) { env.registry.register('adapter:person', DS.Adapter.extend({ queryRecord(store, type, query) { - return Ember.RSVP.reject(); + return reject(); } })); @@ -82,7 +82,7 @@ test("When a record is requested, the serializer's normalizeQueryRecordResponse env.registry.register('adapter:person', DS.Adapter.extend({ queryRecord(store, type, query) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: '1', type: 'person', diff --git a/tests/test-helper.js b/tests/test-helper.js index fd29fcbea65..548cbff7516 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -4,7 +4,10 @@ must be evaluated before the `qunit` module is evaluated (because we change `QUnit.module`). */ -import requiredWorkAroundBabelBug from 'dummy/tests/helpers/setup-ember-dev'; // eslint-disable-line +import RSVP from 'rsvp'; // eslint-disable-line + +import Application from '@ember/application'; +import requiredWorkAroundBabelBug from 'dummy/tests/helpers/setup-ember-dev'; import resolver from './helpers/resolver'; import { setResolver @@ -20,7 +23,7 @@ import Ember from 'ember'; import loadInitializers from 'ember-load-initializers'; setResolver(resolver); -loadInitializers(Ember.Application, 'dummy'); +loadInitializers(Application, 'dummy'); const { assert } = QUnit; const transforms = { @@ -31,7 +34,7 @@ const transforms = { }; QUnit.begin(() => { - Ember.RSVP.configure('onerror', reason => { + RSVP.configure('onerror', reason => { // only print error messages if they're exceptions; // otherwise, let a future turn of the event loop // handle the error. diff --git a/tests/unit/adapter-errors-test.js b/tests/unit/adapter-errors-test.js index 9e19c9a7c47..3e2f252fabe 100644 --- a/tests/unit/adapter-errors-test.js +++ b/tests/unit/adapter-errors-test.js @@ -1,8 +1,8 @@ -import Ember from 'ember'; +import EmberError from '@ember/error'; import { isEnabled } from 'ember-data/-private'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; @@ -12,7 +12,7 @@ test('DS.AdapterError', function(assert) { let error = new DS.AdapterError(); assert.ok(error instanceof Error); - assert.ok(error instanceof Ember.Error); + assert.ok(error instanceof EmberError); assert.ok(error.isAdapterError); assert.equal(error.message, 'Adapter operation failed'); }); diff --git a/tests/unit/adapters/build-url-mixin/path-for-type-test.js b/tests/unit/adapters/build-url-mixin/path-for-type-test.js index a3c07356423..1302a3bf9ee 100644 --- a/tests/unit/adapters/build-url-mixin/path-for-type-test.js +++ b/tests/unit/adapters/build-url-mixin/path-for-type-test.js @@ -1,11 +1,10 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import DS from 'ember-data'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; let env, adapter; -let { run } = Ember; module("unit/adapters/build-url-mixin/path-for-type - DS.BuildURLMixin#pathForType", { beforeEach() { diff --git a/tests/unit/adapters/json-api-adapter/ajax-test.js b/tests/unit/adapters/json-api-adapter/ajax-test.js index 4d2044a6077..c97fd3f1b53 100644 --- a/tests/unit/adapters/json-api-adapter/ajax-test.js +++ b/tests/unit/adapters/json-api-adapter/ajax-test.js @@ -1,12 +1,12 @@ +import { computed } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let Person, Place, store, adapter, env; -const { run } = Ember; module("unit/adapters/json-api-adapter/ajax - building requests", { beforeEach() { @@ -55,7 +55,7 @@ test('ajaxOptions() adds Accept header to existing headers', function(assert) { }); test('ajaxOptions() adds Accept header to existing computed properties headers', function(assert) { - adapter.headers = Ember.computed(function() { + adapter.headers = computed(function() { return { 'Other-key': 'Other Value' }; }); let url = 'example.com'; diff --git a/tests/unit/adapters/rest-adapter/ajax-test.js b/tests/unit/adapters/rest-adapter/ajax-test.js index 1bbed398c3c..f7baae4b4c4 100644 --- a/tests/unit/adapters/rest-adapter/ajax-test.js +++ b/tests/unit/adapters/rest-adapter/ajax-test.js @@ -1,13 +1,13 @@ +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; import { isEnabled } from 'ember-data/-private'; var Person, Place, store, adapter, env; -const { run } = Ember; module('unit/adapters/rest-adapter/ajax - building requests', { beforeEach() { @@ -36,22 +36,22 @@ test('When an id is searched, the correct url should be generated', function(ass if (count === 0) { assert.equal(request.url, '/people/1', 'should create the correct url'); } if (count === 1) { assert.equal(request.url, '/places/1', 'should create the correct url'); } count++; - return Ember.RSVP.resolve(); + return resolve(); }; } else { adapter.ajax = function(url, method) { if (count === 0) { assert.equal(url, '/people/1', 'should create the correct url'); } if (count === 1) { assert.equal(url, '/places/1', 'should create the correct url'); } count++; - return Ember.RSVP.resolve(); + return resolve(); }; } return run(() => { - return Ember.RSVP.Promise.all([ + return EmberPromise.all([ adapter.findRecord(store, Person, 1, {}), adapter.findRecord(store, Place, 1, {}) - ]) + ]); }); }); @@ -61,12 +61,12 @@ test(`id's should be sanatized`, function(assert) { if (isEnabled('ds-improved-ajax')) { adapter._makeRequest = function(request) { assert.equal(request.url, '/people/..%2Fplace%2F1', `should create the correct url`); - return Ember.RSVP.resolve(); + return resolve(); }; } else { adapter.ajax = function(url, method) { assert.equal(url, '/people/..%2Fplace%2F1', "should create the correct url"); - return Ember.RSVP.resolve(); + return resolve(); }; } diff --git a/tests/unit/adapters/rest-adapter/detailed-message-test.js b/tests/unit/adapters/rest-adapter/detailed-message-test.js index 946a510b7ca..cef3e9b4c6d 100644 --- a/tests/unit/adapters/rest-adapter/detailed-message-test.js +++ b/tests/unit/adapters/rest-adapter/detailed-message-test.js @@ -1,6 +1,6 @@ import setupStore from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; diff --git a/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js b/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js index 5010adbcb10..fdcef39969a 100644 --- a/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js +++ b/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js @@ -1,7 +1,8 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { run } from '@ember/runloop'; +import { Promise as EmberPromise } from 'rsvp'; +import { createStore } from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; import { isEnabled } from 'ember-data/-private'; @@ -42,7 +43,7 @@ module('unit/adapters/rest_adapter/group_records_for_find_many_test - DS.RESTAda lengths.push(fullUrl.length); let testRecords = request.data.ids.map(id => ({ id })); - return Ember.RSVP.Promise.resolve({ 'testRecords' : testRecords }); + return EmberPromise.resolve({ 'testRecords' : testRecords }); } }); } else { @@ -62,7 +63,7 @@ module('unit/adapters/rest_adapter/group_records_for_find_many_test - DS.RESTAda lengths.push(fullUrl.length); let testRecords = options.data.ids.map(id => ({ id })); - return Ember.RSVP.Promise.resolve({ 'testRecords' : testRecords }); + return EmberPromise.resolve({ 'testRecords' : testRecords }); } }); } @@ -73,25 +74,25 @@ module('unit/adapters/rest_adapter/group_records_for_find_many_test - DS.RESTAda }); }, afterEach() { - Ember.run(store, 'destroy'); + run(store, 'destroy'); } }); test('groupRecordsForFindMany - findMany', function(assert) { let wait = []; - Ember.run(() => { + run(() => { for (var i = 1; i <= 1024; i++) { wait.push(store.findRecord('testRecord', i)); } }); assert.ok(lengths.every(len => len <= maxLength), `Some URLs are longer than ${maxLength} chars`); - return Ember.RSVP.Promise.all(wait); + return EmberPromise.all(wait); }); test('groupRecordsForFindMany works for encodeURIComponent-ified ids', function(assert) { let wait = []; - Ember.run(() => { + run(() => { wait.push(store.findRecord('testRecord', 'my-id:1')); wait.push(store.findRecord('testRecord', 'my-id:2')); }); @@ -100,11 +101,11 @@ test('groupRecordsForFindMany works for encodeURIComponent-ified ids', function( assert.equal(requests[0].url, '/testRecords'); assert.deepEqual(requests[0].ids, ['my-id:1', 'my-id:2']); - return Ember.RSVP.Promise.all(wait); + return EmberPromise.all(wait); }); test('_stripIDFromURL works with id being encoded - #4190', function(assert) { - let record = Ember.run(() => store.createRecord('testRecord', { id: "id:123" })); + let record = run(() => store.createRecord('testRecord', { id: "id:123" })); let adapter = store.adapterFor('testRecord'); let snapshot = record._internalModel.createSnapshot(); let strippedUrl = adapter._stripIDFromURL(store, snapshot); diff --git a/tests/unit/debug-test.js b/tests/unit/debug-test.js index e399e13d7c9..5925c8441cc 100644 --- a/tests/unit/debug-test.js +++ b/tests/unit/debug-test.js @@ -1,12 +1,11 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { computed } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { run } = Ember; - const TestAdapter = DS.Adapter.extend(); module('Debug'); @@ -57,7 +56,7 @@ test('_debugInfo supports arbitray relationship types', function(assert) { name: DS.attr('string'), isDrugAddict: DS.attr('boolean'), maritalStatus: DS.belongsTo('marital-status', { async: false }), - posts: Ember.computed(() => [1, 2, 3] ) + posts: computed(() => [1, 2, 3] ) .readOnly().meta({ options: { inverse: null }, isRelationship: true, diff --git a/tests/unit/diff-array-test.js b/tests/unit/diff-array-test.js index 1526cb9f9e5..9d69b8f1a3d 100644 --- a/tests/unit/diff-array-test.js +++ b/tests/unit/diff-array-test.js @@ -1,4 +1,4 @@ -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import { diffArray } from 'ember-data/-private'; diff --git a/tests/unit/many-array-test.js b/tests/unit/many-array-test.js index 5ddca06ed74..d0f8b141c74 100644 --- a/tests/unit/many-array-test.js +++ b/tests/unit/many-array-test.js @@ -1,14 +1,14 @@ +import { resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let env, store, Post, Tag; const { attr, hasMany, belongsTo } = DS; -const { run } = Ember; module('unit/many_array - DS.ManyArray', { beforeEach() { @@ -53,7 +53,7 @@ test('manyArray.save() calls save() on all records', function(assert) { Tag.reopen({ save() { assert.ok(true, 'record.save() was called'); - return Ember.RSVP.resolve(); + return resolve(); } }); diff --git a/tests/unit/model-test.js b/tests/unit/model-test.js index da70733455d..f59720afebd 100644 --- a/tests/unit/model-test.js +++ b/tests/unit/model-test.js @@ -1,13 +1,16 @@ -import {createStore} from 'dummy/tests/helpers/store'; +import { guidFor } from '@ember/object/internals'; +import { Promise as EmberPromise, resolve } from 'rsvp'; +import { getOwner } from '@ember/application'; +import { set, get, observer, computed } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; import { isEnabled } from 'ember-data/-private'; -const { get, getOwner, set, run } = Ember; - let Person, store, env; module('unit/model - DS.Model', { @@ -95,7 +98,7 @@ test('resetting a property to the current in-flight value causes it to become cl assert.expect(4); env.adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.Promise.resolve() + return EmberPromise.resolve(); }; return run(() => { @@ -189,7 +192,7 @@ test("a record's id is included in its toString representation", function(assert }); return store.findRecord('person', 1).then(record => { - assert.equal(record.toString(), `<(subclass of DS.Model):${Ember.guidFor(record)}:1>`, 'reports id in toString'); + assert.equal(record.toString(), `<(subclass of DS.Model):${guidFor(record)}:1>`, 'reports id in toString'); }); }); }); @@ -522,7 +525,7 @@ if (isEnabled('ds-rollback-attribute')) { // Make sure the save is async env.adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.resolve(); + return resolve(); }; return run(() => { @@ -557,7 +560,7 @@ if (isEnabled('ds-rollback-attribute')) { assert.expect(7); let person, finishSaving; - let updateRecordPromise = new Ember.RSVP.Promise(resolve => finishSaving = resolve); + let updateRecordPromise = new EmberPromise(resolve => finishSaving = resolve); // Make sure the save is async env.adapter.updateRecord = function(store, type, snapshot) { @@ -608,7 +611,7 @@ if (isEnabled('ds-rollback-attribute')) { finishSaving(); }); - return Ember.RSVP.Promise.all(saving); + return EmberPromise.all(saving); }); } @@ -1182,7 +1185,7 @@ test('ensure model exits loading state, materializes data and fulfills promise o let store = createStore({ adapter: DS.Adapter.extend({ findRecord(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'person', @@ -1346,7 +1349,7 @@ test('internalModel is ready by `init`', function(assert) { this.set('name', 'my-name-set-in-init'); }, - nameDidChange: Ember.observer('name', () => nameDidChange++) + nameDidChange: observer('name', () => nameDidChange++) }); let { store } = setupStore({ person: Person }); @@ -1402,7 +1405,7 @@ test('updating the id with store.updateId should correctly when the id property const Person = DS.Model.extend({ name: DS.attr('string'), - idComputed: Ember.computed('id', function() {}) + idComputed: computed('id', function() {}) }); let { store } = setupStore({ @@ -1426,7 +1429,7 @@ test('accessing the model id without the get function should work when id is wat const Person = DS.Model.extend({ name: DS.attr('string'), - idComputed: Ember.computed('id', function() {}) + idComputed: computed('id', function() {}) }); let { store } = setupStore({ diff --git a/tests/unit/model/errors-test.js b/tests/unit/model/errors-test.js index d51d4246090..71374b7d31e 100644 --- a/tests/unit/model/errors-test.js +++ b/tests/unit/model/errors-test.js @@ -1,5 +1,5 @@ import DS from 'ember-data'; -import QUnit, {module} from 'qunit'; +import QUnit, { module } from 'qunit'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; const AssertPrototype = QUnit.assert; diff --git a/tests/unit/model/lifecycle-callbacks-test.js b/tests/unit/model/lifecycle-callbacks-test.js index 13257dd728d..3ea46df61ba 100644 --- a/tests/unit/model/lifecycle-callbacks-test.js +++ b/tests/unit/model/lifecycle-callbacks-test.js @@ -1,12 +1,12 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { resolve, reject } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; - module('unit/model/lifecycle_callbacks - Lifecycle Callbacks'); test('a record receives a didLoad callback when it has finished loading', function(assert) { @@ -84,7 +84,7 @@ test('a record receives a didUpdate callback when it has finished updating', fun updateRecord(store, type, snapshot) { assert.equal(callCount, 0, 'didUpdate callback was not called until didSaveRecord is called'); - return Ember.RSVP.resolve(); + return resolve(); } }); @@ -126,7 +126,7 @@ test('a record receives a didCreate callback when it has finished updating', fun createRecord(store, type, snapshot) { assert.equal(callCount, 0, 'didCreate callback was not called until didSaveRecord is called'); - return Ember.RSVP.resolve(); + return resolve(); } }); @@ -171,7 +171,7 @@ test('a record receives a didDelete callback when it has finished deleting', fun deleteRecord(store, type, snapshot) { assert.equal(callCount, 0, 'didDelete callback was not called until didSaveRecord is called'); - return Ember.RSVP.resolve(); + return resolve(); } }); @@ -250,7 +250,7 @@ test('a record receives a becameInvalid callback when it became invalid', functi updateRecord(store, type, snapshot) { assert.equal(callCount, 0, 'becameInvalid callback was not called until recordWasInvalid is called'); - return Ember.RSVP.reject(new DS.InvalidError([ + return reject(new DS.InvalidError([ { title: 'Invalid Attribute', detail: 'error', diff --git a/tests/unit/model/merge-test.js b/tests/unit/model/merge-test.js index c2f865dd5d9..bac3ef1f41e 100644 --- a/tests/unit/model/merge-test.js +++ b/tests/unit/model/merge-test.js @@ -1,12 +1,12 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { resolve, Promise as EmberPromise } from 'rsvp'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let Person; -const { run } = Ember; module('unit/model/merge - Merging', { beforeEach() { @@ -55,7 +55,7 @@ test('Make sure snapshot is created at save time not at flush time', function(as updateRecord(store, type, snapshot) { assert.equal(snapshot.attr('name'), 'Thomas Dale'); - return Ember.RSVP.resolve(); + return resolve(); } }); @@ -97,7 +97,7 @@ test("When a record is in flight, pushes are applied underneath the in flight ch const Adapter = DS.Adapter.extend({ updateRecord(store, type, snapshot) { // Make sure saving isn't resolved synchronously - return new Ember.RSVP.Promise(resolve => { + return new EmberPromise(resolve => { run.next(null, resolve, { data: { id: 1, type: 'person', attributes: { name: 'Senor Thomas Dale, Esq.', city: 'Portland' } } }); }); } diff --git a/tests/unit/model/relationships-test.js b/tests/unit/model/relationships-test.js index 0d437b51b59..3edee836733 100644 --- a/tests/unit/model/relationships-test.js +++ b/tests/unit/model/relationships-test.js @@ -1,11 +1,11 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; let Occupation, Person, store; module('unit/model/relationships - DS.Model', { diff --git a/tests/unit/model/relationships/belongs-to-test.js b/tests/unit/model/relationships/belongs-to-test.js index 32606b21674..496558e5ed6 100644 --- a/tests/unit/model/relationships/belongs-to-test.js +++ b/tests/unit/model/relationships/belongs-to-test.js @@ -1,13 +1,12 @@ +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; - module('unit/model/relationships - DS.belongsTo'); test('belongsTo lazily loads relationships as needed', function(assert) { diff --git a/tests/unit/model/relationships/has-many-test.js b/tests/unit/model/relationships/has-many-test.js index 05bfe05a6e4..8c18a4c466e 100644 --- a/tests/unit/model/relationships/has-many-test.js +++ b/tests/unit/model/relationships/has-many-test.js @@ -1,12 +1,13 @@ +import { hash, Promise as EmberPromise } from 'rsvp'; +import { get, observer } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; let env; module('unit/model/relationships - DS.hasMany', { @@ -709,7 +710,7 @@ test('hasMany lazily loads async relationships', function(assert) { assert.equal(get(wycats, 'name'), 'Yehuda Katz', 'precond - retrieves person record from store'); - return Ember.RSVP.hash({ + return hash({ wycats, tags: wycats.get('tags') }); @@ -992,7 +993,7 @@ test('new items added to a hasMany relationship are not cleared by a delete', fu }); env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.deleteRecord = () => { - return Ember.RSVP.Promise.resolve({ data: null }); + return EmberPromise.resolve({ data: null }); }; let { store } = env; @@ -1084,7 +1085,7 @@ test('new items added to an async hasMany relationship are not cleared by a dele }); env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.deleteRecord = () => { - return Ember.RSVP.Promise.resolve({ data: null }); + return EmberPromise.resolve({ data: null }); }; let { store } = env; @@ -1178,7 +1179,7 @@ test('new items added to a belongsTo relationship are not cleared by a delete', }); env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.deleteRecord = () => { - return Ember.RSVP.Promise.resolve({ data: null }); + return EmberPromise.resolve({ data: null }); }; let { store } = env; @@ -1260,7 +1261,7 @@ test('new items added to an async belongsTo relationship are not cleared by a de }); env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.deleteRecord = () => { - return Ember.RSVP.Promise.resolve({ data: null }); + return EmberPromise.resolve({ data: null }); }; let { store } = env; @@ -1342,7 +1343,7 @@ test('deleting an item that is the current state of a belongsTo clears currentSt }); env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.deleteRecord = () => { - return Ember.RSVP.Promise.resolve({ data: null }); + return EmberPromise.resolve({ data: null }); }; let { store } = env; @@ -1499,7 +1500,7 @@ test('[ASSERTS KNOWN LIMITATION STILL EXISTS] returning new hasMany relationship }); env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.deleteRecord = () => { - return Ember.RSVP.Promise.resolve({ + return EmberPromise.resolve({ data: null, included: [ { @@ -1805,7 +1806,7 @@ test('DS.hasMany is stable', function(assert) { assert.equal(people, notifiedPeople); - return Ember.RSVP.Promise.all([ + return EmberPromise.all([ people ]); }); @@ -1827,7 +1828,7 @@ test('DS.hasMany proxy is destroyed', function(assert) { let peopleProxy = tag.get('people'); return peopleProxy.then(people => { - Ember.run(() => { + run(() => { tag.unloadRecord(); assert.equal(people.isDestroying, false, 'people is NOT destroying sync after unloadRecord'); assert.equal(people.isDestroyed, false, 'people is NOT destroyed sync after unloadRecord'); @@ -1837,7 +1838,7 @@ test('DS.hasMany proxy is destroyed', function(assert) { assert.equal(peopleProxy.isDestroying, true, 'peopleProxy is destroying after the run post unloadRecord'); assert.equal(peopleProxy.isDestroyed, true, 'peopleProxy is destroyed after the run post unloadRecord'); - }) + }); }); test('DS.ManyArray is lazy', function(assert) { @@ -1845,7 +1846,7 @@ test('DS.ManyArray is lazy', function(assert) { const Tag = DS.Model.extend({ name: DS.attr('string'), people: DS.hasMany('person'), - peopleDidChange: Ember.observer('people', function() { + peopleDidChange: observer('people', function() { peopleDidChange++; }) }); @@ -1870,9 +1871,9 @@ test('DS.ManyArray is lazy', function(assert) { assert.equal(peopleDidChange, 0, 'expect people hasMany to not emit a change event (after access, but after the current run loop)'); assert.ok(hasManyRelationship._manyArray instanceof DS.ManyArray); - let person = Ember.run(() => env.store.createRecord('person')); + let person = run(() => env.store.createRecord('person')); - Ember.run(() => { + run(() => { assert.equal(peopleDidChange, 0, 'expect people hasMany to not emit a change event (before access)'); tag.get('people').addObject(person); assert.equal(peopleDidChange, 1, 'expect people hasMany to have changed exactly once'); diff --git a/tests/unit/model/relationships/record-array-test.js b/tests/unit/model/relationships/record-array-test.js index dafc81f7271..7cdf36da71c 100644 --- a/tests/unit/model/relationships/record-array-test.js +++ b/tests/unit/model/relationships/record-array-test.js @@ -1,12 +1,12 @@ +import { A } from '@ember/array'; +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, set, run } = Ember; - module('unit/model/relationships - RecordArray'); test('updating the content of a RecordArray updates its content', function(assert) { @@ -42,7 +42,7 @@ test('updating the content of a RecordArray updates its content', function(asser }] }); tags = DS.RecordArray.create({ - content: Ember.A(internalModels.slice(0, 2)), + content: A(internalModels.slice(0, 2)), store: store, modelName: 'tag' }); @@ -51,7 +51,7 @@ test('updating the content of a RecordArray updates its content', function(asser let tag = tags.objectAt(0); assert.equal(get(tag, 'name'), 'friendly', `precond - we're working with the right tags`); - run(() => set(tags, 'content', Ember.A(internalModels.slice(1, 3)))); + run(() => set(tags, 'content', A(internalModels.slice(1, 3)))); tag = tags.objectAt(0); assert.equal(get(tag, 'name'), 'smarmy', 'the lookup was updated'); diff --git a/tests/unit/model/rollback-attributes-test.js b/tests/unit/model/rollback-attributes-test.js index b884d133f89..985d8f5eb9b 100644 --- a/tests/unit/model/rollback-attributes-test.js +++ b/tests/unit/model/rollback-attributes-test.js @@ -1,13 +1,15 @@ +import { isEmpty, isPresent } from '@ember/utils'; +import { addObserver } from '@ember/object/observers'; +import { Promise as EmberPromise, reject } from 'rsvp'; +import { run, later } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; import { isEnabled } from 'ember-data/-private'; let env, store, Person; -const { run } = Ember; module('unit/model/rollbackAttributes - model.rollbackAttributes()', { beforeEach() { @@ -75,7 +77,7 @@ test('changes to unassigned attributes can be rolled back', function(assert) { test('changes to attributes made after a record is in-flight only rolls back the local changes', function(assert) { env.adapter.updateRecord = function(store, type, snapshot) { // Make sure the save is async - return new Ember.RSVP.Promise(resolve => Ember.run.later(null, resolve, 15)); + return new EmberPromise(resolve => later(null, resolve, 15)); }; let person = run(() => { @@ -119,7 +121,7 @@ test('changes to attributes made after a record is in-flight only rolls back the test("a record's changes can be made if it fails to save", function(assert) { env.adapter.updateRecord = function(store, type, snapshot) { - return Ember.RSVP.reject(); + return reject(); }; let person = run(() => { @@ -159,7 +161,7 @@ test("a record's changes can be made if it fails to save", function(assert) { test(`a deleted record's attributes can be rollbacked if it fails to save, record arrays are updated accordingly`, function(assert) { assert.expect(8); env.adapter.deleteRecord = function(store, type, snapshot) { - return Ember.RSVP.reject(); + return reject(); }; let person, people; @@ -204,7 +206,7 @@ test(`new record's attributes can be rollbacked`, function(assert) { assert.equal(person.get('isNew'), true, 'must be new'); assert.equal(person.get('hasDirtyAttributes'), true, 'must be dirty'); - Ember.run(person, 'rollbackAttributes'); + run(person, 'rollbackAttributes'); assert.equal(person.get('isNew'), false, 'must not be new'); assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty'); @@ -223,13 +225,13 @@ test(`invalid new record's attributes can be rollbacked`, function(assert) { if (isEnabled('ds-improved-ajax')) { adapter = DS.RESTAdapter.extend({ _makeRequest() { - return Ember.RSVP.reject(error); + return reject(error); } }); } else { adapter = DS.RESTAdapter.extend({ ajax(url, type, hash) { - return Ember.RSVP.reject(error); + return reject(error); } }); } @@ -261,14 +263,14 @@ test(`invalid record's attributes can be rollbacked after multiple failed calls adapter = DS.RESTAdapter.extend({ _makeRequest() { let error = new DS.InvalidError(); - return Ember.RSVP.reject(error); + return reject(error); } }); } else { adapter = DS.RESTAdapter.extend({ ajax(url, type, hash) { let error = new DS.InvalidError(); - return Ember.RSVP.reject(error); + return reject(error); } }); } @@ -351,13 +353,13 @@ test("invalid record's attributes can be rollbacked", function(assert) { if (isEnabled('ds-improved-ajax')) { adapter = DS.RESTAdapter.extend({ _makeRequest() { - return Ember.RSVP.reject(error); + return reject(error); } }); } else { adapter = DS.RESTAdapter.extend({ ajax(url, type, hash) { - return Ember.RSVP.reject(error); + return reject(error); } }); } @@ -380,7 +382,7 @@ test("invalid record's attributes can be rollbacked", function(assert) { }); return run(() => { - Ember.addObserver(dog, 'errors.name', function() { + addObserver(dog, 'errors.name', function() { assert.ok(true, 'errors.name did change'); }); @@ -400,7 +402,7 @@ test("invalid record's attributes can be rollbacked", function(assert) { assert.equal(dog.get('hasDirtyAttributes'), false, 'must not be dirty'); assert.equal(dog.get('name'), 'Pluto'); - assert.ok(Ember.isEmpty(dog.get('errors.name'))); + assert.ok(isEmpty(dog.get('errors.name'))); assert.ok(dog.get('isValid')); }); }); @@ -424,13 +426,13 @@ test(`invalid record's attributes rolled back to correct state after set`, funct if (isEnabled('ds-improved-ajax')) { adapter = DS.RESTAdapter.extend({ _makeRequest() { - return Ember.RSVP.reject(error); + return reject(error); } }); } else { adapter = DS.RESTAdapter.extend({ ajax(url, type, hash) { - return Ember.RSVP.reject(error); + return reject(error); } }); } @@ -454,7 +456,7 @@ test(`invalid record's attributes rolled back to correct state after set`, funct }); return run(() => { - Ember.addObserver(dog, 'errors.name', function() { + addObserver(dog, 'errors.name', function() { assert.ok(true, 'errors.name did change'); }); @@ -462,7 +464,7 @@ test(`invalid record's attributes rolled back to correct state after set`, funct assert.equal(reason, error); assert.equal(dog.get('name'), 'is a dwarf planet'); assert.equal(dog.get('breed'), 'planet'); - assert.ok(Ember.isPresent(dog.get('errors.name'))); + assert.ok(isPresent(dog.get('errors.name'))); assert.equal(dog.get('errors.name.length'), 1); run(() => dog.set('name', 'Seymour Asses')); @@ -475,7 +477,7 @@ test(`invalid record's attributes rolled back to correct state after set`, funct assert.equal(dog.get('name'), 'Pluto'); assert.equal(dog.get('breed'), 'Disney'); assert.equal(dog.get('hasDirtyAttributes'), false, 'must not be dirty'); - assert.ok(Ember.isEmpty(dog.get('errors.name'))); + assert.ok(isEmpty(dog.get('errors.name'))); assert.ok(dog.get('isValid')); }); }); @@ -497,13 +499,13 @@ test(`when destroying a record setup the record state to invalid, the record's a if (isEnabled('ds-improved-ajax')) { adapter = DS.RESTAdapter.extend({ _makeRequest() { - return Ember.RSVP.reject(error); + return reject(error); } }); } else { adapter = DS.RESTAdapter.extend({ ajax(url, type, hash) { - return Ember.RSVP.reject(error); + return reject(error); } }); } diff --git a/tests/unit/private-test.js b/tests/unit/private-test.js index bd42b3a33b2..30e468493ff 100644 --- a/tests/unit/private-test.js +++ b/tests/unit/private-test.js @@ -1,5 +1,9 @@ import { module, test } from 'qunit'; -import { ContainerInstanceCache, InternalModel, RootState } from 'ember-data/-private'; +import { + ContainerInstanceCache, + InternalModel, + RootState +} from 'ember-data/-private'; module('-private'); diff --git a/tests/unit/promise-proxies-test.js b/tests/unit/promise-proxies-test.js index 79d103e882e..b6b772f4dae 100644 --- a/tests/unit/promise-proxies-test.js +++ b/tests/unit/promise-proxies-test.js @@ -1,6 +1,7 @@ -import Ember from 'ember'; +import { Promise as EmberPromise } from 'rsvp'; +import { A } from '@ember/array'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; @@ -9,9 +10,9 @@ module('PromiseManyArray'); test('.reload should NOT leak the internal promise, rather return another promiseArray', function(assert) { assert.expect(2); - let content = Ember.A(); + let content = A(); - content.reload = () => Ember.RSVP.Promise.resolve(content); + content.reload = () => EmberPromise.resolve(content); let array = new DS.PromiseManyArray({ content @@ -27,10 +28,10 @@ test('.reload should NOT leak the internal promise, rather return another promis test('.reload should be stable', function(assert) { assert.expect(19); - let content = Ember.A(); + let content = A(); - content.reload = () => Ember.RSVP.Promise.resolve(content); - let promise = Ember.RSVP.Promise.resolve(content); + content.reload = () => EmberPromise.resolve(content); + let promise = EmberPromise.resolve(content); let array = new DS.PromiseManyArray({ promise @@ -71,9 +72,9 @@ test('.reload should be stable', function(assert) { test('.set to new promise should be like reload', function(assert) { assert.expect(18); - let content = Ember.A([1,2,3]); + let content = A([1,2,3]); - let promise = Ember.RSVP.Promise.resolve(content); + let promise = EmberPromise.resolve(content); let array = new DS.PromiseManyArray({ promise @@ -90,7 +91,7 @@ test('.set to new promise should be like reload', function(assert) { assert.equal(array.get('isSettled'), true, 'should be settled'); assert.equal(array.get('isFulfilled'), true, 'should be fulfilled'); - array.set('promise', Ember.RSVP.Promise.resolve(content)); + array.set('promise', EmberPromise.resolve(content)); assert.equal(array.get('isRejected'), false, 'should NOT be rejected'); assert.equal(array.get('isPending'), true, 'should be pending'); diff --git a/tests/unit/record-arrays/adapter-populated-record-array-test.js b/tests/unit/record-arrays/adapter-populated-record-array-test.js index bea0d34070b..f1ed2a8ce79 100644 --- a/tests/unit/record-arrays/adapter-populated-record-array-test.js +++ b/tests/unit/record-arrays/adapter-populated-record-array-test.js @@ -1,9 +1,9 @@ +import { A } from '@ember/array'; +import RSVP from 'rsvp'; +import { run } from '@ember/runloop'; import DS from 'ember-data'; -import {module, test} from 'qunit'; -import Ember from 'ember'; - -const { RSVP, run } = Ember; +import { module, test } from 'qunit'; const { AdapterPopulatedRecordArray } = DS; module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedRecordArray'); @@ -34,7 +34,7 @@ test('default initial state', function(assert) { }); test('custom initial state', function(assert) { - let content = Ember.A([]); + let content = A([]); let store = {}; let recordArray = AdapterPopulatedRecordArray.create({ modelName: 'apple', diff --git a/tests/unit/record-arrays/filtered-record-array-test.js b/tests/unit/record-arrays/filtered-record-array-test.js index afa43b570f1..6a388cc70df 100644 --- a/tests/unit/record-arrays/filtered-record-array-test.js +++ b/tests/unit/record-arrays/filtered-record-array-test.js @@ -1,9 +1,10 @@ +import { run } from '@ember/runloop'; +import { A } from '@ember/array'; +import { get } from '@ember/object'; import DS from 'ember-data'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; -const { get } = Ember; const { FilteredRecordArray } = DS; module('unit/record-arrays/filtered-record-array - DS.FilteredRecordArray'); @@ -19,7 +20,7 @@ test('default initial state', function(assert) { }); test('custom initial state', function(assert) { - let content = Ember.A(); + let content = A(); let store = {}; let filterFunction = () => true; let recordArray = FilteredRecordArray.create({ @@ -63,12 +64,12 @@ test('updateFilter', function(assert) { let recordArray = FilteredRecordArray.create({ modelName: 'recordType', manager, - content: Ember.A() + content: A() }); assert.equal(didUpdateFilter, 0, 'no filterFunction should have been changed yet'); - Ember.run(() => { + run(() => { recordArray.set('filterFunction', updatedFilterFunction); assert.equal(didUpdateFilter, 0, 'record array manager should not yet be informed of the filterFunction change'); recordArray.set('filterFunction', updatedFilterFunction); @@ -78,7 +79,7 @@ test('updateFilter', function(assert) { assert.equal(didUpdateFilter, 1, 'record array manager should have been informed once that the array filterFunction has changed'); didUpdateFilter = 0; - Ember.run(() => { + run(() => { recordArray.set('filterFunction', updatedFilterFunction); assert.equal(didUpdateFilter, 0, 'record array manager should not be informed of this change'); recordArray.destroy(); diff --git a/tests/unit/record-arrays/record-array-test.js b/tests/unit/record-arrays/record-array-test.js index b11f0eb6487..91bd69c6d7b 100644 --- a/tests/unit/record-arrays/record-array-test.js +++ b/tests/unit/record-arrays/record-array-test.js @@ -1,8 +1,10 @@ +import { A } from '@ember/array'; +import { get } from '@ember/object'; +import RSVP from 'rsvp'; +import { run } from '@ember/runloop'; import DS from 'ember-data'; -import Ember from 'ember'; import { module, test } from 'qunit'; -const { get, RSVP, run } = Ember; const { RecordArray } = DS; module('unit/record-arrays/record-array - DS.RecordArray'); @@ -18,7 +20,7 @@ test('default initial state', function(assert) { }); test('custom initial state', function(assert) { - let content = Ember.A(); + let content = A(); let store = {}; let recordArray = RecordArray.create({ modelName: 'apple', @@ -43,7 +45,7 @@ test('#replace() throws error', function(assert) { }); test('#objectAtContent', function(assert) { - let content = Ember.A([ + let content = A([ { getRecord() { return 'foo'; }}, { getRecord() { return 'bar'; }}, { getRecord() { return 'baz'; }} @@ -137,7 +139,7 @@ test('#update while updating', function(assert) { }); test('#_pushInternalModels', function(assert) { - let content = Ember.A(); + let content = A(); let recordArray = RecordArray.create({ content }); @@ -161,7 +163,7 @@ test('#_pushInternalModels', function(assert) { }); test('#_removeInternalModels', function(assert) { - let content = Ember.A(); + let content = A(); let recordArray = RecordArray.create({ content }); @@ -215,7 +217,7 @@ function internalModelFor(record) { test('#save', function(assert) { let model1 = { save() { model1Saved++; return this;} }; let model2 = { save() { model2Saved++; return this;} }; - let content = Ember.A([ + let content = A([ internalModelFor(model1), internalModelFor(model2) ]); @@ -256,7 +258,7 @@ test('#destroy', function(assert) { // end TODO: let recordArray = RecordArray.create({ - content: Ember.A([internalModel1]), + content: A([internalModel1]), manager: { unregisterRecordArray(_recordArray) { didUnregisterRecordArray++; @@ -293,7 +295,7 @@ test('#_createSnapshot', function(assert) { id: 2 }; - let content = Ember.A([ + let content = A([ internalModelFor(model1), internalModelFor(model2) ]); @@ -327,7 +329,7 @@ test('#destroy', function(assert) { // end TODO: let recordArray = RecordArray.create({ - content: Ember.A([internalModel1]), + content: A([internalModel1]), manager: { unregisterRecordArray(_recordArray) { didUnregisterRecordArray++; diff --git a/tests/unit/states-test.js b/tests/unit/states-test.js index abfbb1e3c94..c655068d54b 100644 --- a/tests/unit/states-test.js +++ b/tests/unit/states-test.js @@ -1,9 +1,8 @@ -import Ember from 'ember'; -import QUnit, {module, test} from 'qunit'; +import { get } from '@ember/object'; +import QUnit, { module, test } from 'qunit'; import DS from 'ember-data'; const { assert } = QUnit; -const { get } = Ember; let rootState, stateName; diff --git a/tests/unit/store/adapter-interop-test.js b/tests/unit/store/adapter-interop-test.js index 43c80a267a2..fc7ba5fb307 100644 --- a/tests/unit/store/adapter-interop-test.js +++ b/tests/unit/store/adapter-interop-test.js @@ -1,14 +1,20 @@ -import {createStore} from 'dummy/tests/helpers/store'; +import { A } from '@ember/array'; +import { + resolve, + all, + Promise as EmberPromise +} from 'rsvp'; +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, set , run } = Ember; -const resolve = Ember.RSVP.resolve; let TestAdapter, store, oldFilterEnabled; module('unit/store/adapter-interop - DS.Store working with a DS.Adapter', { @@ -59,7 +65,7 @@ test('Calling Store#find invokes its adapter#find', function(assert) { assert.equal(id, 1, "Adapter#find was called with the id passed into Store#find"); assert.equal(snapshot.id, '1', "Adapter#find was called with the record created from Store#find"); - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'test' @@ -88,7 +94,7 @@ test('Calling Store#findRecord multiple times coalesces the calls into a adapter findMany(store, type, ids, snapshots) { assert.ok(true, 'Adapter#findMany was called'); assert.deepEqual(ids, ['1','2'], 'Correct ids were passed in to findMany'); - return Ember.RSVP.resolve({ data: [{ id: 1, type: 'test' }, { id: 2, type: 'test' }] }); + return resolve({ data: [{ id: 1, type: 'test' }, { id: 2, type: 'test' }] }); }, coalesceFindRequests: true }); @@ -100,7 +106,7 @@ test('Calling Store#findRecord multiple times coalesces the calls into a adapter }); return run(() => { - return Ember.RSVP.all([ + return all([ store.findRecord('test', 1), store.findRecord('test', 2) ]); @@ -232,7 +238,7 @@ test('loadMany takes an optional Object and passes it on to the Adapter', functi query(store, type, query) { assert.equal(type, store.modelFor('person'), 'The type was Person'); assert.equal(query, passedQuery, 'The query was passed in'); - return Ember.RSVP.resolve({ data: [] }); + return resolve({ data: [] }); } }); @@ -253,7 +259,7 @@ test('Find with query calls the correct normalizeResponse', function(assert) { const Adapter = TestAdapter.extend({ query(store, type, query) { - return Ember.RSVP.resolve([]); + return resolve([]); } }); @@ -652,7 +658,7 @@ test('records should have their ids updated when the adapter returns the id data }); return run(() => { - return Ember.RSVP.all([ + return all([ tom.save(), yehuda.save() ]).then(() => { @@ -695,7 +701,7 @@ test('store._scheduleFetchMany should not resolve until all the records are reso findRecord(store, type, id, snapshot) { let record = { id, type: type.modelName }; - return new Ember.RSVP.Promise(resolve => { + return new EmberPromise(resolve => { run.later(() => resolve({ data: record }), 5); }); }, @@ -703,7 +709,7 @@ test('store._scheduleFetchMany should not resolve until all the records are reso findMany(store, type, ids, snapshots) { let records = ids.map(id => ( { id, type: type.modelName }) ); - return new Ember.RSVP.Promise(resolve => { + return new EmberPromise(resolve => { run.later(() => { resolve({data: records }); }, 15); @@ -727,7 +733,7 @@ test('store._scheduleFetchMany should not resolve until all the records are reso return run(() => { return store._scheduleFetchMany(internalModels).then(() => { - let unloadedRecords = Ember.A(internalModels.map(r => r.getRecord())).filterBy('isEmpty'); + let unloadedRecords = A(internalModels.map(r => r.getRecord())).filterBy('isEmpty'); assert.equal(get(unloadedRecords, 'length'), 0, 'All unloaded records should be loaded'); }); @@ -797,7 +803,7 @@ test('the promise returned by `_scheduleFetch`, when it resolves, does not depen findRecord(store, type, id, snapshot) { let record = { id, type: 'test' }; - return new Ember.RSVP.Promise(function(resolve, reject) { + return new EmberPromise(function(resolve, reject) { if (id === 'igor') { resolve({ data: record }); } else { @@ -828,7 +834,7 @@ test('the promise returned by `_scheduleFetch`, when it resolves, does not depen assert.equal(davidResolved, true, 'David resolved'); })); - return Ember.RSVP.all(wait); + return all(wait); }); }); @@ -849,7 +855,7 @@ test('the promise returned by `_scheduleFetch`, when it rejects, does not depend findRecord(store, type, id, snapshot) { let record = { id, type: 'test' }; - return new Ember.RSVP.Promise((resolve, reject) => { + return new EmberPromise((resolve, reject) => { if (id === 'igor') { reject({ data: record }); } else { @@ -880,7 +886,7 @@ test('the promise returned by `_scheduleFetch`, when it rejects, does not depend assert.equal(davidResolved, true, 'David resolved'); })); - return Ember.RSVP.Promise.all(wait); + return EmberPromise.all(wait); }); }); @@ -912,7 +918,7 @@ testInDebug('store._fetchRecord reject records that were not found, even when th }); }, /expected to find records with the following ids/); - return Ember.RSVP.Promise.all(wait); + return EmberPromise.all(wait); }); testInDebug('store._fetchRecord warns when records are missing', function(assert) { @@ -944,7 +950,7 @@ testInDebug('store._fetchRecord warns when records are missing', function(assert }); }, /expected to find records with the following ids in the adapter response but they were missing/); - return Ember.RSVP.Promise.all(wait).then(() => { + return EmberPromise.all(wait).then(() => { assert.ok(igorDidReject, 'expected rejection that could not be found in the payload, but no such rejection occured'); }); }); diff --git a/tests/unit/store/asserts-test.js b/tests/unit/store/asserts-test.js index 5ebaaa5203c..c84fbb22637 100644 --- a/tests/unit/store/asserts-test.js +++ b/tests/unit/store/asserts-test.js @@ -1,6 +1,6 @@ -import {module} from 'qunit'; +import { module } from 'qunit'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {createStore} from 'dummy/tests/helpers/store'; +import { createStore } from 'dummy/tests/helpers/store'; module('unit/store/asserts - DS.Store methods produce useful assertion messages'); diff --git a/tests/unit/store/create-record-test.js b/tests/unit/store/create-record-test.js index 2d6c4014c81..5fdcc219fa9 100644 --- a/tests/unit/store/create-record-test.js +++ b/tests/unit/store/create-record-test.js @@ -1,11 +1,11 @@ -import {createStore} from 'dummy/tests/helpers/store'; +import { A } from '@ember/array'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let store, Record, Storage; -const { run } = Ember; module('unit/store/createRecord - Store creating records', { beforeEach() { @@ -65,8 +65,8 @@ test('allow passing relationships as well as attributes', function(assert) { }); assert.equal(storage.get('name'), 'Great store', 'The attribute is well defined'); - assert.equal(storage.get('records').findBy('id', '1'), Ember.A(records).findBy('id', '1'), 'Defined relationships are allowed in createRecord'); - assert.equal(storage.get('records').findBy('id', '2'), Ember.A(records).findBy('id', '2'), 'Defined relationships are allowed in createRecord'); + assert.equal(storage.get('records').findBy('id', '1'), A(records).findBy('id', '1'), 'Defined relationships are allowed in createRecord'); + assert.equal(storage.get('records').findBy('id', '2'), A(records).findBy('id', '2'), 'Defined relationships are allowed in createRecord'); }); module('unit/store/createRecord - Store with models by dash', { diff --git a/tests/unit/store/finders-test.js b/tests/unit/store/finders-test.js index b6d724d305d..9ee8ee9b859 100644 --- a/tests/unit/store/finders-test.js +++ b/tests/unit/store/finders-test.js @@ -1,10 +1,8 @@ +import { defer } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; - -const { run } = Ember; -const { defer } = Ember.RSVP; +import { module, test } from 'qunit'; import DS from 'ember-data'; diff --git a/tests/unit/store/has-model-for-test.js b/tests/unit/store/has-model-for-test.js index 0cd5dd127a5..0fa53f5a2cd 100644 --- a/tests/unit/store/has-model-for-test.js +++ b/tests/unit/store/has-model-for-test.js @@ -1,5 +1,5 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { createStore } from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let store; diff --git a/tests/unit/store/has-record-for-id-test.js b/tests/unit/store/has-record-for-id-test.js index 4d288bf5ae1..3aab6feb164 100644 --- a/tests/unit/store/has-record-for-id-test.js +++ b/tests/unit/store/has-record-for-id-test.js @@ -1,13 +1,12 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let env, store, Person, PhoneNumber; const { attr, hasMany, belongsTo } = DS; -const { run } = Ember; module('unit/store/hasRecordForId - Store hasRecordForId', { beforeEach() { @@ -33,7 +32,7 @@ module('unit/store/hasRecordForId - Store hasRecordForId', { }, afterEach() { - Ember.run(store, 'destroy'); + run(store, 'destroy'); } }); diff --git a/tests/unit/store/lookup-test.js b/tests/unit/store/lookup-test.js index b5e7a450ce5..86a210d279e 100644 --- a/tests/unit/store/lookup-test.js +++ b/tests/unit/store/lookup-test.js @@ -1,12 +1,11 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let store, env, applicationAdapter, applicationSerializer, Person; -const { run } = Ember; function resetStore() { if (store) { diff --git a/tests/unit/store/model-for-test.js b/tests/unit/store/model-for-test.js index 6b337200da1..0c74eeaeb2c 100644 --- a/tests/unit/store/model-for-test.js +++ b/tests/unit/store/model-for-test.js @@ -1,15 +1,13 @@ +import { run } from '@ember/runloop'; +import { dasherize, camelize } from '@ember/string'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let container, store, registry, env; -const { camelize, dasherize } = Ember.String; -const { run } = Ember; - module('unit/store/model_for - DS.Store#modelFor', { beforeEach() { env = setupStore({ diff --git a/tests/unit/store/peek-record-test.js b/tests/unit/store/peek-record-test.js index 490ee94fe00..1d5ec9433f5 100644 --- a/tests/unit/store/peek-record-test.js +++ b/tests/unit/store/peek-record-test.js @@ -1,12 +1,11 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let env, store, Person; -const { run } = Ember; module('unit/store/peekRecord - Store peekRecord', { beforeEach() { @@ -20,7 +19,7 @@ module('unit/store/peekRecord - Store peekRecord', { }, afterEach() { - Ember.run(store, 'destroy'); + run(store, 'destroy'); } }); diff --git a/tests/unit/store/push-test.js b/tests/unit/store/push-test.js index e884f3627c0..a579dd8e7cb 100644 --- a/tests/unit/store/push-test.js +++ b/tests/unit/store/push-test.js @@ -1,8 +1,12 @@ +import { inspect } from '@ember/debug'; +import EmberObject from '@ember/object'; +import { Promise as EmberPromise, resolve } from 'rsvp'; +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; @@ -10,7 +14,6 @@ import { isEnabled } from 'ember-data/-private'; let env, store, Person, PhoneNumber, Post; const { attr, hasMany, belongsTo } = DS; -const { run } = Ember; module('unit/store/push - DS.Store#push', { beforeEach() { @@ -144,7 +147,7 @@ test('Supplying a model class for `push` is the same as supplying a string', fun test(`Calling push triggers 'didLoad' even if the record hasn't been requested from the adapter`, function(assert) { assert.expect(1); - let didLoad = new Ember.RSVP.Promise((resolve, reject) => { + let didLoad = new EmberPromise((resolve, reject) => { Person.reopen({ didLoad() { try { @@ -250,7 +253,7 @@ test('Calling push with a normalized hash containing IDs of related records retu env.adapter.findRecord = function(store, type, id) { if (id === '1') { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: 'phone-number', @@ -265,7 +268,7 @@ test('Calling push with a normalized hash containing IDs of related records retu } if (id === "2") { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 2, type: 'phone-number', @@ -505,8 +508,8 @@ test('calling push without data argument as an object raises an error', function null, 1, 'string', - Ember.Object.create(), - Ember.Object.extend(), + EmberObject.create(), + EmberObject.extend(), true ]; @@ -638,8 +641,8 @@ testInDebug('calling push with hasMany relationship the value must be an array', let invalidValues = [ 1, 'string', - Ember.Object.create(), - Ember.Object.extend(), + EmberObject.create(), + EmberObject.extend(), true ]; @@ -665,7 +668,7 @@ testInDebug('calling push with hasMany relationship the value must be an array', store._pushedInternalModels.length = 0; throw e; } - }, /must be an array/, `Expect that '${Ember.inspect(invalidValue)}' is not an array`); + }, /must be an array/, `Expect that '${inspect(invalidValue)}' is not an array`); }); }); diff --git a/tests/unit/store/serialize-test.js b/tests/unit/store/serialize-test.js index 1967d7ac5ac..d92f3b5f488 100644 --- a/tests/unit/store/serialize-test.js +++ b/tests/unit/store/serialize-test.js @@ -1,13 +1,11 @@ +import { run } from '@ember/runloop'; import { module } from 'qunit'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import attr from 'ember-data/attr'; import Model from 'ember-data/model'; import { createStore } from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import { isEnabled } from 'ember-data/-private'; -const { run } = Ember; - if (isEnabled('ds-deprecate-store-serialize')) { module("unit/store/serialize - DS.Store#serialize"); diff --git a/tests/unit/store/serializer-for-test.js b/tests/unit/store/serializer-for-test.js index 6206ffd4b8c..0bebe7a918a 100644 --- a/tests/unit/store/serializer-for-test.js +++ b/tests/unit/store/serializer-for-test.js @@ -1,13 +1,12 @@ +import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; let container, store, registry, Person; -const { run } = Ember; module('unit/store/serializer_for - DS.Store#serializerFor', { beforeEach() { diff --git a/tests/unit/store/unload-test.js b/tests/unit/store/unload-test.js index f0bfe1240a0..98d88e3f3e0 100644 --- a/tests/unit/store/unload-test.js +++ b/tests/unit/store/unload-test.js @@ -1,12 +1,13 @@ -import {createStore} from 'dummy/tests/helpers/store'; -import Ember from 'ember'; +import { resolve } from 'rsvp'; +import { get } from '@ember/object'; +import { run } from '@ember/runloop'; +import { createStore } from 'dummy/tests/helpers/store'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; -const { get, run } = Ember; let store, tryToFind, Record; module('unit/store/unload - Store unloading records', { @@ -27,7 +28,7 @@ module('unit/store/unload - Store unloading records', { adapter: DS.Adapter.extend({ findRecord(store, type, id, snapshot) { tryToFind = true; - return Ember.RSVP.resolve({ data: { id, type: snapshot.modelName, attributes: { 'was-fetched': true } } }); + return resolve({ data: { id, type: snapshot.modelName, attributes: { 'was-fetched': true } } }); } }), @@ -36,7 +37,7 @@ module('unit/store/unload - Store unloading records', { }, afterEach() { - Ember.run(store, 'destroy'); + run(store, 'destroy'); } }); @@ -155,7 +156,7 @@ test('can commit store after unload record with relationships', function(assert) let store = createStore({ adapter: DS.Adapter.extend({ findRecord(store, type, id, snapshot) { - return Ember.RSVP.resolve({ + return resolve({ data: { id: 1, type: snapshot.modelName, @@ -168,7 +169,7 @@ test('can commit store after unload record with relationships', function(assert) }, createRecord(store, type, snapshot) { - return Ember.RSVP.resolve(); + return resolve(); } }), brand: Brand, @@ -206,7 +207,7 @@ test('can commit store after unload record with relationships', function(assert) return like.save(); }).then(() => { // TODO: this is strange, future travelers please address - Ember.run(() => store.unloadRecord(store.peekRecord('product', 1))); + run(() => store.unloadRecord(store.peekRecord('product', 1))); }).then(() => { return store.findRecord('product', 1); }).then(product => { diff --git a/tests/unit/system/relationships/relationship-payload-manager-test.js b/tests/unit/system/relationships/relationship-payload-manager-test.js index 8aa78aafa21..9ade62feb01 100644 --- a/tests/unit/system/relationships/relationship-payload-manager-test.js +++ b/tests/unit/system/relationships/relationship-payload-manager-test.js @@ -1,10 +1,8 @@ -import Ember from 'ember'; +import { get } from '@ember/object'; import { RelationshipPayloadsManager } from 'ember-data/-private'; import DS from 'ember-data'; -import {createStore} from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; - -const { get } = Ember; +import { createStore } from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; module('unit/system/relationships/relationship-payloads-manager', { beforeEach() { diff --git a/tests/unit/system/relationships/relationship-payloads-test.js b/tests/unit/system/relationships/relationship-payloads-test.js index 2ee7e9fb939..6f7715760d0 100644 --- a/tests/unit/system/relationships/relationship-payloads-test.js +++ b/tests/unit/system/relationships/relationship-payloads-test.js @@ -1,12 +1,10 @@ -import Ember from 'ember'; +import { get } from '@ember/object'; import { RelationshipPayloadsManager } from 'ember-data/-private'; import DS from 'ember-data'; -import {createStore} from 'dummy/tests/helpers/store'; -import {module, test} from 'qunit'; +import { createStore } from 'dummy/tests/helpers/store'; +import { module, test } from 'qunit'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -const { get } = Ember; - module('unit/system/relationships/relationship-payloads', { beforeEach() { const User = DS.Model.extend({ diff --git a/tests/unit/system/snapshot-record-array-test.js b/tests/unit/system/snapshot-record-array-test.js index c33fb225aea..7c8221a428c 100644 --- a/tests/unit/system/snapshot-record-array-test.js +++ b/tests/unit/system/snapshot-record-array-test.js @@ -1,11 +1,11 @@ +import { A } from '@ember/array'; import { SnapshotRecordArray } from 'ember-data/-private'; -import Ember from 'ember'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; module('Unit - snapshot-record-array'); test('constructor', function(assert) { - let array = Ember.A([1, 2]); + let array = A([1, 2]); array.type = 'some type'; let meta = { }; let options = { @@ -23,7 +23,7 @@ test('constructor', function(assert) { }); test('#snapshot', function(assert) { - let array = Ember.A([1, 2]); + let array = A([1, 2]); let didTakeSnapshot = 0; let snapshotTaken = {}; @@ -49,7 +49,7 @@ test('#snapshot', function(assert) { }); test('SnapshotRecordArray.type loads the class lazily', function(assert) { - let array = Ember.A([1, 2]); + let array = A([1, 2]); let typeLoaded = false; Object.defineProperty(array, 'type', { diff --git a/tests/unit/transform/boolean-test.js b/tests/unit/transform/boolean-test.js index 4c2ae3c5b40..02bd4ae73c1 100644 --- a/tests/unit/transform/boolean-test.js +++ b/tests/unit/transform/boolean-test.js @@ -1,6 +1,6 @@ import DS from 'ember-data'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; module('unit/transform - DS.BooleanTransform'); diff --git a/tests/unit/transform/date-test.js b/tests/unit/transform/date-test.js index 46746ced520..330c8ec2469 100644 --- a/tests/unit/transform/date-test.js +++ b/tests/unit/transform/date-test.js @@ -1,4 +1,4 @@ -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; import Ember from 'ember'; diff --git a/tests/unit/transform/number-test.js b/tests/unit/transform/number-test.js index 17d3e47d381..c8a3aba2a7e 100644 --- a/tests/unit/transform/number-test.js +++ b/tests/unit/transform/number-test.js @@ -1,6 +1,6 @@ import DS from 'ember-data'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; module('unit/transform - DS.NumberTransform'); diff --git a/tests/unit/transform/string-test.js b/tests/unit/transform/string-test.js index 713d97f7f64..8aa87545101 100644 --- a/tests/unit/transform/string-test.js +++ b/tests/unit/transform/string-test.js @@ -1,6 +1,6 @@ import DS from 'ember-data'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; module('unit/transform - DS.StringTransform'); diff --git a/tests/unit/utils-test.js b/tests/unit/utils-test.js index 4bf54576bec..573796df4b3 100644 --- a/tests/unit/utils-test.js +++ b/tests/unit/utils-test.js @@ -1,14 +1,17 @@ +import { run } from '@ember/runloop'; +import Mixin from '@ember/object/mixin'; import setupStore from 'dummy/tests/helpers/store'; -import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import {module, test} from 'qunit'; +import { module, test } from 'qunit'; import DS from 'ember-data'; import Model from 'ember-data/model'; import { assertPolymorphicType } from 'ember-data/-debug'; -import { modelHasAttributeOrRelationshipNamedType } from 'ember-data/-private'; +import { + modelHasAttributeOrRelationshipNamedType +} from 'ember-data/-private'; let env, User, Message, Post, Person, Video, Medium; @@ -24,7 +27,7 @@ module('unit/utils', { medias: DS.hasMany('medium', { async: false }) }); - Medium = Ember.Mixin.create(); + Medium = Mixin.create(); Video = Model.extend(Medium); env = setupStore({ @@ -39,14 +42,14 @@ module('unit/utils', { }, afterEach() { - Ember.run(env.container, 'destroy'); + run(env.container, 'destroy'); } }); testInDebug('assertPolymorphicType works for subclasses', function(assert) { let user, post, person; - Ember.run(() => { + run(() => { env.store.push({ data: [{ type: 'user', @@ -107,7 +110,7 @@ test('modelHasAttributeOrRelationshipNamedType', function(assert) { testInDebug('assertPolymorphicType works for mixins', function(assert) { let post, video, person; - Ember.run(() => { + run(() => { env.store.push({ data: [{ type: 'post',