From d6d85fc5a68aaad4b5dc10b8d03c1db14f48033c Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:29:43 -0800 Subject: [PATCH 01/25] cleanup test-helpers --- tests/helpers/async.js | 21 ++++++++++----------- tests/helpers/custom-adapter.js | 6 ++---- tests/helpers/setup-ember-dev.js | 10 +++++----- tests/helpers/store.js | 8 ++++---- tests/helpers/test-in-debug.js | 4 +--- tests/test-helper.js | 26 ++++++++++++++------------ 6 files changed, 36 insertions(+), 39 deletions(-) diff --git a/tests/helpers/async.js b/tests/helpers/async.js index 0beedd41849..75f10b9960d 100644 --- a/tests/helpers/async.js +++ b/tests/helpers/async.js @@ -3,7 +3,7 @@ import Ember from 'ember'; export function wait(callback, timeout) { let done = this.async(); - var timer = setTimeout(() => { + let timer = setTimeout(() => { this.ok(false, "Timeout was reached"); done(); }, timeout || 200); @@ -11,12 +11,10 @@ export function wait(callback, timeout) { return function() { window.clearTimeout(timer); - var args = arguments; - var result; + let args = arguments; + let result; try { - result = Ember.run(function() { - return callback.apply(this, args); - }); + result = Ember.run(() => callback.apply(this, args)); } finally { done(); } @@ -25,14 +23,15 @@ export function wait(callback, timeout) { } export function asyncEqual(a, b, message) { - return Ember.RSVP.all([Ember.RSVP.resolve(a), Ember.RSVP.resolve(b)]).then(this.wait((array) => { + return Ember.RSVP.all([ + Ember.RSVP.resolve(a), + Ember.RSVP.resolve(b) + ]).then(this.wait((array) => { this.push(array[0] === array[1], array[0], array[1], message); })); } -export function invokeAsync(callback, timeout) { - timeout = timeout || 1; - - setTimeout(this.wait(callback, timeout+100), timeout); +export function invokeAsync(callback, timeout = 1) { + setTimeout(this.wait(callback, timeout + 100), timeout); } diff --git a/tests/helpers/custom-adapter.js b/tests/helpers/custom-adapter.js index 9272e8d1bbe..99ca0eaa207 100644 --- a/tests/helpers/custom-adapter.js +++ b/tests/helpers/custom-adapter.js @@ -1,14 +1,12 @@ import Ember from 'ember'; - import DS from 'ember-data'; - export default function(env, adapterDefinition) { - var adapter = adapterDefinition; + let adapter = adapterDefinition; if (!DS.Adapter.detect(adapterDefinition)) { adapter = DS.Adapter.extend(adapterDefinition); } - var store = env.store; + let store = env.store; env.registry.register('adapter:-custom', adapter); Ember.run(() => store.set('adapter', '-custom')); } diff --git a/tests/helpers/setup-ember-dev.js b/tests/helpers/setup-ember-dev.js index 703c9c4dac6..bfa724ff2c5 100644 --- a/tests/helpers/setup-ember-dev.js +++ b/tests/helpers/setup-ember-dev.js @@ -5,7 +5,7 @@ import EmberTestHelpers from "ember-dev/test-helper/index"; const AVAILABLE_ASSERTIONS = ['expectAssertion', 'expectDeprecation', 'expectNoDeprecation', 'expectWarning', 'expectNoWarning', 'ignoreDeprecation']; // Maintain backwards compatiblity with older versions of ember. -var emberDebugModule; +let emberDebugModule; if (Ember.__loader && Ember.__loader.registry && Ember.__loader.registry["ember-metal/debug"]) { emberDebugModule = Ember.__loader.require('ember-metal/debug'); } @@ -26,7 +26,7 @@ function setDebugFunction(name, func) { } } -var originalModule = QUnit.module; +const originalModule = QUnit.module; /** * We patch QUnit.module here so we can setup and teardown the helpers from @@ -37,14 +37,14 @@ var originalModule = QUnit.module; * make the corresponding test fail. */ QUnit.module = function(name, options = {}) { - var testHelpers = new EmberTestHelpers({ + let testHelpers = new EmberTestHelpers({ Ember, getDebugFunction, setDebugFunction }); - var originalBeforeEach = options.beforeEach || function() { }; - var originalAfterEach = options.afterEach || function() { }; + let originalBeforeEach = options.beforeEach || function() { }; + let originalAfterEach = options.afterEach || function() { }; options.beforeEach = function(assert) { testHelpers.reset(); diff --git a/tests/helpers/store.js b/tests/helpers/store.js index 4b87186e428..4948ab027f9 100644 --- a/tests/helpers/store.js +++ b/tests/helpers/store.js @@ -3,8 +3,8 @@ import DS from 'ember-data'; import Owner from './owner'; export default function setupStore(options) { - var container, registry, owner; - var env = {}; + let container, registry, owner; + let env = {}; options = options || {}; if (Ember.Registry) { @@ -29,7 +29,7 @@ export default function setupStore(options) { } }; - var adapter = env.adapter = (options.adapter || '-default'); + let adapter = env.adapter = (options.adapter || '-default'); delete options.adapter; if (typeof adapter !== 'string') { @@ -37,7 +37,7 @@ export default function setupStore(options) { adapter = '-ember-data-test-custom'; } - for (var prop in options) { + for (let prop in options) { registry.register('model:' + Ember.String.dasherize(prop), options[prop]); } diff --git a/tests/helpers/test-in-debug.js b/tests/helpers/test-in-debug.js index d8bdd45a595..810896035f5 100644 --- a/tests/helpers/test-in-debug.js +++ b/tests/helpers/test-in-debug.js @@ -4,9 +4,7 @@ import { test, skip } from 'qunit'; export default function testInDebug() { let isDebug = false; - runInDebug(function() { - isDebug = true; - }); + runInDebug(() => isDebug = true); if (isDebug) { test(...arguments); diff --git a/tests/test-helper.js b/tests/test-helper.js index 3e26b1b29d4..a05079eb995 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -17,9 +17,15 @@ setResolver(resolver); loadInitializers(Ember.Application, 'dummy'); const { assert } = QUnit; +const transforms = { + boolean: DS.BooleanTransform.create(), + date: DS.DateTransform.create(), + number: DS.NumberTransform.create(), + string: DS.StringTransform.create() +}; -QUnit.begin(function() { - Ember.RSVP.configure('onerror', function(reason) { +QUnit.begin(() => { + Ember.RSVP.configure('onerror', reason => { // only print error messages if they're exceptions; // otherwise, let a future turn of the event loop // handle the error. @@ -29,13 +35,6 @@ QUnit.begin(function() { } }); - var transforms = { - 'boolean': DS.BooleanTransform.create(), - 'date': DS.DateTransform.create(), - 'number': DS.NumberTransform.create(), - 'string': DS.StringTransform.create() - }; - // Prevent all tests involving serialization to require a container DS.JSONSerializer.reopen({ transformFor(attributeType) { @@ -49,8 +48,8 @@ assert.wait = wait; assert.asyncEqual = asyncEqual; assert.invokeAsync = invokeAsync; assert.assertClean = function(promise) { - return promise.then(this.wait((record) => { - this.equal(record.get('hasDirtyAttributes'), false, "The record is now clean"); + return promise.then(this.wait(record => { + this.equal(record.get('hasDirtyAttributes'), false, 'The record is now clean'); return record; })); }; @@ -64,4 +63,7 @@ assert.without = function(array, item) { }; QUnit.config.testTimeout = 2000; -QUnit.config.urlConfig.push({ id: 'enableoptionalfeatures', label: "Enable Opt Features" }); +QUnit.config.urlConfig.push({ + id: 'enableoptionalfeatures', + label: 'Enable Opt Features' +}); From 7899db460ef984fe079aadea5607fb3e3156fab6 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:30:26 -0800 Subject: [PATCH 02/25] cleanup test/unit/model-test.js * consistent promise/run-loop usage * let/const * misc consistency --- tests/unit/model-test.js | 981 +++++++++++++++++++-------------------- 1 file changed, 483 insertions(+), 498 deletions(-) diff --git a/tests/unit/model-test.js b/tests/unit/model-test.js index 6e0e8b1b434..f08e5bbc15f 100644 --- a/tests/unit/model-test.js +++ b/tests/unit/model-test.js @@ -8,12 +8,9 @@ import isEnabled from 'ember-data/-private/features'; import { parseDate } from "ember-data/-private/ext/date"; const AssertionPrototype = QUnit.assert; +const { get, set, run } = Ember; -var get = Ember.get; -var set = Ember.set; -var run = Ember.run; - -var Person, store, env; +let Person, store, env; module('unit/model - DS.Model', { beforeEach() { @@ -29,28 +26,25 @@ module('unit/model - DS.Model', { }, afterEach() { - run(function() { - store.destroy(); - }); - Person = null; - store = null; + run(() => store.destroy()); } }); -test("can have a property set on it", function(assert) { - var record; - run(function() { - record = store.createRecord('person'); +test('can have a property set on it', function(assert) { + let record = run(() => { + let record = store.createRecord('person'); set(record, 'name', 'bar'); + return record; }); - assert.equal(get(record, 'name'), 'bar', "property was set on the record"); + assert.equal(get(record, 'name'), 'bar', 'property was set on the record'); }); -test("setting a property on a record that has not changed does not cause it to become dirty", function(assert) { +test('setting a property on a record that has not changed does not cause it to become dirty', function(assert) { assert.expect(2); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { + + return run(() => { store.push({ data: { type: 'person', @@ -62,22 +56,22 @@ test("setting a property on a record that has not changed does not cause it to b } }); - store.findRecord('person', 1).then(function(person) { - assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty"); + return store.findRecord('person', 1).then(person => { + assert.equal(person.get('hasDirtyAttributes'), false, 'precond - person record should not be dirty'); person.set('name', "Peter"); person.set('isDrugAddict', true); - assert.equal(person.get('hasDirtyAttributes'), false, "record does not become dirty after setting property to old value"); + assert.equal(person.get('hasDirtyAttributes'), false, 'record does not become dirty after setting property to old value'); }); }); }); -test("resetting a property on a record cause it to become clean again", function(assert) { +test('resetting a property on a record cause it to become clean again', function(assert) { assert.expect(3); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { + return run(() => { store.push({ data: { type: 'person', @@ -88,29 +82,25 @@ test("resetting a property on a record cause it to become clean again", function } } }); - store.findRecord('person', 1).then(function(person) { - assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty"); + + return store.findRecord('person', 1).then(person => { + assert.equal(person.get('hasDirtyAttributes'), false, 'precond - person record should not be dirty'); person.set('isDrugAddict', false); - assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting property to a new value"); + assert.equal(person.get('hasDirtyAttributes'), true, 'record becomes dirty after setting property to a new value'); person.set('isDrugAddict', true); - assert.equal(person.get('hasDirtyAttributes'), false, "record becomes clean after resetting property to the old value"); + assert.equal(person.get('hasDirtyAttributes'), false, 'record becomes clean after resetting property to the old value'); }); }); }); -test("resetting a property to the current in-flight value causes it to become clean when the save completes", function(assert) { +test('resetting a property to the current in-flight value causes it to become clean when the save completes', function(assert) { assert.expect(4); - var person, finishSaving; - env.adapter.updateRecord = function(store, type, snapshot) { - // Make sure the save is async - return new Ember.RSVP.Promise(function(resolve, reject) { - finishSaving = resolve; - }); + return Ember.RSVP.Promise.resolve() }; - run(function() { + return run(() => { store.push({ data: { type: 'person', @@ -120,34 +110,31 @@ test("resetting a property to the current in-flight value causes it to become cl } } }); - person = store.peekRecord('person', 1); + + let person = store.peekRecord('person', 1); person.set('name', "Thomas"); - person.save(); - }); + let saving = person.save() - run(function() { - assert.equal(person.get('name'), "Thomas"); + assert.equal(person.get('name'), 'Thomas'); person.set('name', 'Tomathy'); - assert.equal(person.get('name'), "Tomathy"); + assert.equal(person.get('name'), 'Tomathy'); person.set('name', 'Thomas'); - assert.equal(person.get('name'), "Thomas"); - - finishSaving(); - }); + assert.equal(person.get('name'), 'Thomas'); - run(function() { - assert.equal(person.get('hasDirtyAttributes'), false, "The person is now clean"); + return saving.then(() => { + assert.equal(person.get('hasDirtyAttributes'), false, 'The person is now clean'); + }); }); }); -test("a record becomes clean again only if all changed properties are reset", function(assert) { +test('a record becomes clean again only if all changed properties are reset', function(assert) { assert.expect(5); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { + return run(() => { store.push({ data: { type: 'person', @@ -158,33 +145,35 @@ test("a record becomes clean again only if all changed properties are reset", fu } } }); - store.findRecord('person', 1).then(function(person) { - assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty"); + + return store.findRecord('person', 1).then(person => { + assert.equal(person.get('hasDirtyAttributes'), false, 'precond - person record should not be dirty'); person.set('isDrugAddict', false); - assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting one property to a new value"); + assert.equal(person.get('hasDirtyAttributes'), true, 'record becomes dirty after setting one property to a new value'); person.set('name', 'Mark'); - assert.equal(person.get('hasDirtyAttributes'), true, "record stays dirty after setting another property to a new value"); + assert.equal(person.get('hasDirtyAttributes'), true, 'record stays dirty after setting another property to a new value'); person.set('isDrugAddict', true); - assert.equal(person.get('hasDirtyAttributes'), true, "record stays dirty after resetting only one property to the old value"); + assert.equal(person.get('hasDirtyAttributes'), true, 'record stays dirty after resetting only one property to the old value'); person.set('name', 'Peter'); assert.equal(person.get('hasDirtyAttributes'), false, "record becomes clean after resetting both properties to the old value"); }); }); }); -test("a record reports its unique id via the `id` property", function(assert) { +test('a record reports its unique id via the `id` property', function(assert) { assert.expect(1); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { + return run(() => { store.push({ data: { type: 'person', id: '1' } }); - store.findRecord('person', 1).then(function(record) { - assert.equal(get(record, 'id'), 1, "reports id as id by default"); + + return store.findRecord('person', 1).then(record => { + assert.equal(get(record, 'id'), 1, 'reports id as id by default'); }); }); }); @@ -193,31 +182,32 @@ test("a record's id is included in its toString representation", function(assert assert.expect(1); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { + return run(() => { store.push({ data: { type: 'person', id: '1' } }); - store.findRecord('person', 1).then(function(record) { - assert.equal(record.toString(), '<(subclass of DS.Model):'+Ember.guidFor(record)+':1>', "reports id in toString"); + + return store.findRecord('person', 1).then(record => { + assert.equal(record.toString(), `<(subclass of DS.Model):${Ember.guidFor(record)}:1>`, 'reports id in toString'); }); }); }); -testInDebug("trying to set an `id` attribute should raise", function(assert) { +testInDebug('trying to set an `id` attribute should raise', function(assert) { Person = DS.Model.extend({ id: DS.attr('number'), name: DS.attr('string') }); - var store = createStore({ + const store = createStore({ person: Person }); - assert.expectAssertion(function() { - run(function() { + assert.expectAssertion(() => { + run(() => { store.push({ data: { type: 'person', @@ -232,16 +222,16 @@ testInDebug("trying to set an `id` attribute should raise", function(assert) { }, /You may not set `id`/); }); -test("a collision of a record's id with object function's name", function(assert) { +test(`a collision of a record's id with object function's name`, function(assert) { assert.expect(1); env.adapter.shouldBackgroundReloadRecord = () => false; - var hasWatchMethod = Object.prototype.watch; + let hasWatchMethod = Object.prototype.watch; try { if (!hasWatchMethod) { Object.prototype.watch = function() {}; } - run(function() { + return run(() => { store.push({ data: { type: 'person', @@ -249,8 +239,8 @@ test("a collision of a record's id with object function's name", function(assert } }); - store.findRecord('person', 'watch').then(function(record) { - assert.equal(get(record, 'id'), 'watch', "record is successfully created and could be found by its id"); + return store.findRecord('person', 'watch').then(record => { + assert.equal(get(record, 'id'), 'watch', 'record is successfully created and could be found by its id'); }); }); } finally { @@ -260,48 +250,48 @@ test("a collision of a record's id with object function's name", function(assert } }); -/* -test("it should use `_internalModel` and not `internalModel` to store its internalModel", function() { - expect(1); - - run(function() { - store.push('person', { id: 1 }); - - store.findRecord(Person, 1).then(function(record) { - equal(record.get('_internalModel'), undefined, "doesn't shadow internalModel key"); +test('it should use `_internalModel` and not `internalModel` to store its internalModel', function(assert) { + run(() => { + store.push({ + data: { + type: 'person', + id: 1, + attributes: {} + } }); + + assert.equal(store.peekRecord('person', 1).get('internalModel'), undefined, `doesn't shadow internalModel key`); }); }); -*/ -test("it should cache attributes", function(assert) { +test('it should cache attributes', function(assert) { assert.expect(2); - var Post = DS.Model.extend({ + const Post = DS.Model.extend({ updatedAt: DS.attr('string') }); - var store = createStore({ + const store = createStore({ post: Post }); - var dateString = "Sat, 31 Dec 2011 00:08:16 GMT"; - var date = new Date(dateString); + let dateString = 'Sat, 31 Dec 2011 00:08:16 GMT'; + let date = new Date(dateString); - run(function() { + return run(() => { store.push({ data: { type: 'post', id: '1' } }); - store.findRecord('post', 1).then(function(record) { - run(function() { - record.set('updatedAt', date); - }); - assert.deepEqual(date, get(record, 'updatedAt'), "setting a date returns the same date"); - assert.strictEqual(get(record, 'updatedAt'), get(record, 'updatedAt'), "second get still returns the same object"); - }).finally(function() { + + return store.findRecord('post', 1).then(record => { + record.set('updatedAt', date); + + assert.deepEqual(date, get(record, 'updatedAt'), 'setting a date returns the same date'); + assert.strictEqual(get(record, 'updatedAt'), get(record, 'updatedAt'), 'second get still returns the same object'); + }).finally(() => { run(store, 'destroy'); }); }); @@ -310,20 +300,17 @@ test("it should cache attributes", function(assert) { test("changedAttributes() return correct values", function(assert) { assert.expect(4); - var Mascot = DS.Model.extend({ + const Mascot = DS.Model.extend({ name: DS.attr('string'), likes: DS.attr('string'), isMascot: DS.attr('boolean') }); - var store = createStore({ + let store = createStore({ mascot: Mascot }); - var mascot; - - - run(function() { + let mascot = run(() => { store.push({ data: { type: 'mascot', @@ -334,84 +321,99 @@ test("changedAttributes() return correct values", function(assert) { } } }); - mascot = store.peekRecord('mascot', 1); + + return store.peekRecord('mascot', 1); }); assert.equal(Object.keys(mascot.changedAttributes()).length, 0, 'there are no initial changes'); - run(function() { + run(() => { mascot.set('name', 'Tomster'); // new value mascot.set('likes', 'Ember.js'); // changed value mascot.set('isMascot', true); // same value }); - var changedAttributes = mascot.changedAttributes(); + + let changedAttributes = mascot.changedAttributes(); + assert.deepEqual(changedAttributes.name, [undefined, 'Tomster']); assert.deepEqual(changedAttributes.likes, ['JavaScript', 'Ember.js']); - run(function() { - mascot.rollbackAttributes(); - }); + run(() => mascot.rollbackAttributes()); + assert.equal(Object.keys(mascot.changedAttributes()).length, 0, 'after rollback attributes there are no changes'); }); function toObj(obj) { // https://github.com/jquery/qunit/issues/851 - var result = Object.create(null); - for (var key in obj) { + let result = Object.create(null); + for (let key in obj) { result[key] = obj[key]; } return result; } -test("changedAttributes() works while the record is being saved", function(assert) { +test('changedAttributes() works while the record is being saved', function(assert) { assert.expect(1); - var cat; - var adapter = DS.Adapter.extend({ + + let cat; + const Adapter = DS.Adapter.extend({ createRecord(store, model, snapshot) { assert.deepEqual(toObj(cat.changedAttributes()), { name: [undefined, 'Argon'], - likes: [undefined, 'Cheese'] }); + likes: [undefined, 'Cheese'] + }); + return { id: 1 }; } }); - var Mascot = DS.Model.extend({ + + const Mascot = DS.Model.extend({ name: DS.attr('string'), likes: DS.attr('string'), isMascot: DS.attr('boolean') }); - var store = createStore({ + let store = createStore({ mascot: Mascot, - adapter: adapter + adapter: Adapter }); - run(function() { + return run(() => { cat = store.createRecord('mascot'); - cat.setProperties({ name: 'Argon', likes: 'Cheese' }); - cat.save(); + cat.setProperties({ + name: 'Argon', + likes: 'Cheese' + }); + + return cat.save(); }); }); -test("changedAttributes() works while the record is being updated", function(assert) { +test('changedAttributes() works while the record is being updated', function(assert) { assert.expect(1); - var cat; - var adapter = DS.Adapter.extend({ + let cat; + const Adapter = DS.Adapter.extend({ updateRecord(store, model, snapshot) { - assert.deepEqual(toObj(cat.changedAttributes()), { name: ['Argon', 'Helia'], likes: ['Cheese', 'Mussels'] }); + assert.deepEqual(toObj(cat.changedAttributes()), { + name: ['Argon', 'Helia'], + likes: ['Cheese', 'Mussels'] + }); + return { id: '1', type: 'mascot' }; } }); - var Mascot = DS.Model.extend({ + + const Mascot = DS.Model.extend({ name: DS.attr('string'), likes: DS.attr('string'), isMascot: DS.attr('boolean') }); - var store = createStore({ + let store = createStore({ mascot: Mascot, - adapter: adapter + adapter: Adapter }); - run(function() { + return run(() => { store.push({ data: { type: 'mascot', @@ -422,17 +424,21 @@ test("changedAttributes() works while the record is being updated", function(ass } } }); + cat = store.peekRecord('mascot', 1); - cat.setProperties({ name: 'Helia', likes: 'Mussels' }); - cat.save(); + cat.setProperties({ + name: 'Helia', + likes: 'Mussels' + }); + return cat.save(); }); }); if (isEnabled('ds-rollback-attribute')) { - test("rollbackAttribute() reverts a single attribute to its canonical value", function(assert) { + test('rollbackAttribute() reverts a single attribute to its canonical value', function(assert) { assert.expect(5); - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -446,23 +452,23 @@ if (isEnabled('ds-rollback-attribute')) { let person = store.peekRecord('person', 1); - assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty"); + assert.equal(person.get('hasDirtyAttributes'), false, 'precond - person record should not be dirty'); person.setProperties({ name: 'Piper', isDrugAddict: false }); - assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting property to a new value"); + assert.equal(person.get('hasDirtyAttributes'), true, 'record becomes dirty after setting property to a new value'); person.rollbackAttribute('isDrugAddict'); - assert.equal(person.get('isDrugAddict'), true, "The specified attribute is rolled back"); - assert.equal(person.get('name'), 'Piper', "Unspecified attributes are not rolled back"); - assert.equal(person.get('hasDirtyAttributes'), true, "record with changed attributes is still dirty"); + assert.equal(person.get('isDrugAddict'), true, 'The specified attribute is rolled back'); + assert.equal(person.get('name'), 'Piper', 'Unspecified attributes are not rolled back'); + assert.equal(person.get('hasDirtyAttributes'), true, 'record with changed attributes is still dirty'); }); }); - test("calling rollbackAttribute() on an unmodified property has no effect", function(assert) { + test('calling rollbackAttribute() on an unmodified property has no effect', function(assert) { assert.expect(5); - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -476,20 +482,20 @@ if (isEnabled('ds-rollback-attribute')) { let person = store.peekRecord('person', 1); - assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty"); + assert.equal(person.get('hasDirtyAttributes'), false, 'precond - person record should not be dirty'); person.set('name', 'Piper'); - assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting property to a new value"); + assert.equal(person.get('hasDirtyAttributes'), true, 'record becomes dirty after setting property to a new value'); person.rollbackAttribute('isDrugAddict'); - assert.equal(person.get('isDrugAddict'), true, "The specified attribute does not change value"); - assert.equal(person.get('name'), 'Piper', "Unspecified attributes are not rolled back"); - assert.equal(person.get('hasDirtyAttributes'), true, "record with changed attributes is still dirty"); + assert.equal(person.get('isDrugAddict'), true, 'The specified attribute does not change value'); + assert.equal(person.get('name'), 'Piper', 'Unspecified attributes are not rolled back'); + assert.equal(person.get('hasDirtyAttributes'), true, 'record with changed attributes is still dirty'); }); }); - test("Rolling back the final value with rollbackAttribute() causes the record to become clean again", function(assert) { + test('Rolling back the final value with rollbackAttribute() causes the record to become clean again', function(assert) { assert.expect(3); - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -503,27 +509,26 @@ if (isEnabled('ds-rollback-attribute')) { let person = store.peekRecord('person', 1); - assert.equal(person.get('hasDirtyAttributes'), false, "precond - person record should not be dirty"); + assert.equal(person.get('hasDirtyAttributes'), false, 'precond - person record should not be dirty'); person.set('isDrugAddict', false); - assert.equal(person.get('hasDirtyAttributes'), true, "record becomes dirty after setting property to a new value"); + assert.equal(person.get('hasDirtyAttributes'), true, 'record becomes dirty after setting property to a new value'); person.rollbackAttribute('isDrugAddict'); - assert.equal(person.get('hasDirtyAttributes'), false, "record becomes clean after resetting property to the old value"); + assert.equal(person.get('hasDirtyAttributes'), false, 'record becomes clean after resetting property to the old value'); }); }); - test("Using rollbackAttribute on an in-flight record reverts to the latest in-flight value", function(assert) { + test('Using rollbackAttribute on an in-flight record reverts to the latest in-flight value', function(assert) { assert.expect(4); - var person, finishSaving; + let person, finishSaving; + let updateRecordPromise = new Ember.RSVP.Promise(resolve => finishSaving = resolve); // Make sure the save is async env.adapter.updateRecord = function(store, type, snapshot) { - return new Ember.RSVP.Promise(function(resolve, reject) { - finishSaving = resolve; - }); + return updateRecordPromise; }; - run(function() { + return run(() => { store.push({ data: { type: 'person', @@ -534,38 +539,37 @@ if (isEnabled('ds-rollback-attribute')) { } }); person = store.peekRecord('person', 1); - person.set('name', "Thomas"); + person.set('name', 'Thomas'); - person.save(); - }); + let saving = person.save(); - run(function() { assert.equal(person.get('isSaving'), true); - assert.equal(person.get('name'), "Thomas"); + assert.equal(person.get('name'), 'Thomas'); - person.set('name', "Tomathy"); - assert.equal(person.get('name'), "Tomathy"); + person.set('name', 'Tomathy'); + assert.equal(person.get('name'), 'Tomathy'); person.rollbackAttribute('name'); - assert.equal(person.get('name'), "Thomas"); + assert.equal(person.get('name'), 'Thomas'); finishSaving(); + + return saving; }); }); - test("Saving an in-flight record updates the in-flight value rollbackAttribute will use", function(assert) { + test('Saving an in-flight record updates the in-flight value rollbackAttribute will use', function(assert) { assert.expect(7); - var person, finishSaving; + let person, finishSaving; + let updateRecordPromise = new Ember.RSVP.Promise(resolve => finishSaving = resolve); // Make sure the save is async env.adapter.updateRecord = function(store, type, snapshot) { - return new Ember.RSVP.Promise(function(resolve, reject) { - finishSaving = resolve; - }); + return updateRecordPromise; }; - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -575,94 +579,92 @@ if (isEnabled('ds-rollback-attribute')) { } } }); + person = store.peekRecord('person', 1); - person.set('name', "Thomas"); + }); - person.save(); + let saving = []; + + run(() => { + person.set('name', 'Thomas'); + saving.push(person.save()); }); - run(function() { + run(() => { assert.equal(person.get('isSaving'), true); - assert.equal(person.get('name'), "Thomas"); + assert.equal(person.get('name'), 'Thomas'); - person.set('name', "Tomathy"); - assert.equal(person.get('name'), "Tomathy"); + person.set('name', 'Tomathy'); + assert.equal(person.get('name'), 'Tomathy'); - person.save(); + saving.push(person.save()); }); - run(function() { + run(() => { assert.equal(person.get('isSaving'), true); assert.equal(person.get('name'), "Tomathy"); person.set('name', "Tomny"); - assert.equal(person.get('name'), "Tomny"); + assert.equal(person.get('name'), 'Tomny'); person.rollbackAttribute('name'); assert.equal(person.get('name'), 'Tomathy'); finishSaving(); }); + + return Ember.RSVP.Promise.all(saving); }); } test("a DS.Model does not require an attribute type", function(assert) { - var Tag = DS.Model.extend({ + const Tag = DS.Model.extend({ name: DS.attr() }); - var store = createStore({ + let store = createStore({ tag: Tag }); - var tag; + let tag = run(() => store.createRecord('tag', { name: "test" })); - run(function() { - tag = store.createRecord('tag', { name: "test" }); - }); - - assert.equal(get(tag, 'name'), "test", "the value is persisted"); + assert.equal(get(tag, 'name'), 'test', 'the value is persisted'); }); -test("a DS.Model can have a defaultValue without an attribute type", function(assert) { - var Tag = DS.Model.extend({ +test('a DS.Model can have a defaultValue without an attribute type', function(assert) { + const Tag = DS.Model.extend({ name: DS.attr({ defaultValue: "unknown" }) }); - var store = createStore({ + let store = createStore({ tag: Tag }); - var tag; - run(function() { - tag = store.createRecord('tag'); - }); + let tag = run(() => store.createRecord('tag')); - assert.equal(get(tag, 'name'), "unknown", "the default value is found"); + assert.equal(get(tag, 'name'), 'unknown', 'the default value is found'); }); -testInDebug("Calling attr() throws a warning", function(assert) { +testInDebug('Calling attr() throws a warning', function(assert) { assert.expect(1); - run(function() { - var person = store.createRecord('person', { id: 1, name: 'TomHuda' }); + let person = run(() => store.createRecord('person', { id: 1, name: 'TomHuda' })); - assert.throws(function() { - person.attr(); - }, /The `attr` method is not available on DS.Model, a DS.Snapshot was probably expected/, "attr() throws a warning"); - }); + assert.throws(() => { + person.attr(); + }, /The `attr` method is not available on DS.Model, a DS.Snapshot was probably expected/, 'attr() throws a warning'); }); -test("supports pushedData in root.deleted.uncommitted", function(assert) { - var record; - var hash = { +test('supports pushedData in root.deleted.uncommitted', function(assert) { + let hash = { data: { type: 'person', id: '1' } }; - run(function() { - record = store.push(hash); + + run(() => { + let record = store.push(hash); record.deleteRecord(); store.push(hash); assert.equal(get(record, 'currentState.stateName'), 'root.deleted.uncommitted', @@ -670,243 +672,235 @@ test("supports pushedData in root.deleted.uncommitted", function(assert) { }); }); -test("currentState is accessible when the record is created", function(assert) { - var record; - var hash = { +test('currentState is accessible when the record is created', function(assert) { + let hash = { data: { type: 'person', id: '1' } }; - run(function() { - record = store.push(hash); + + run(() => { + let record = store.push(hash); assert.equal(get(record, 'currentState.stateName'), 'root.loaded.saved', - 'records pushed into the store start in the loaded state'); + 'records pushed into the store start in the loaded state'); }); }); -module("unit/model - DS.Model updating", { +module('unit/model - DS.Model updating', { beforeEach() { - Person = DS.Model.extend({ name: DS.attr('string') }); + Person = DS.Model.extend({ + name: DS.attr('string') + }); + env = setupStore({ person: Person }); + store = env.store; - run(function() { + run(() => { store.push({ - data: [{ - type: 'person', - id: '1', - attributes: { - name: 'Scumbag Dale' - } - }, { - type: 'person', - id: '2', - attributes: { - name: 'Scumbag Katz' - } - }, { - type: 'person', - id: '3', - attributes: { - name: 'Scumbag Bryn' - } - }] + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale' + } + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz' + } + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn' + } + }] }); }); }, + afterEach() { - run(function() { - store.destroy(); - Person = null; - store = null; - }); + run(store, 'destroy'); } }); -test("a DS.Model can update its attributes", function(assert) { +test('a DS.Model can update its attributes', function(assert) { assert.expect(1); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { - store.findRecord('person', 2).then(function(person) { - set(person, 'name', "Brohuda Katz"); - assert.equal(get(person, 'name'), "Brohuda Katz", "setting took hold"); + return run(() => { + return store.findRecord('person', 2).then(person => { + set(person, 'name', 'Brohuda Katz'); + assert.equal(get(person, 'name'), 'Brohuda Katz', 'setting took hold'); }); }); }); -test("a DS.Model can have a defaultValue", function(assert) { - var Tag = DS.Model.extend({ - name: DS.attr('string', { defaultValue: "unknown" }) +test('a DS.Model can have a defaultValue', function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string', { defaultValue: 'unknown' }) }); - var tag; - var store = createStore({ + let store = createStore({ tag: Tag }); - run(function() { - tag = store.createRecord('tag'); - }); + let tag = run(() => store.createRecord('tag')); - assert.equal(get(tag, 'name'), "unknown", "the default value is found"); + assert.equal(get(tag, 'name'), 'unknown', 'the default value is found'); - run(function() { - set(tag, 'name', null); - }); + run(() => set(tag, 'name', null)); - assert.equal(get(tag, 'name'), null, "null doesn't shadow defaultValue"); + assert.equal(get(tag, 'name'), null, `null doesn't shadow defaultValue`); }); -test("a DS.model can define 'setUnknownProperty'", function(assert) { - var tag; - var Tag = DS.Model.extend({ - name: DS.attr("string"), +test(`a DS.model can define 'setUnknownProperty'`, function(assert) { + const Tag = DS.Model.extend({ + name: DS.attr('string'), setUnknownProperty(key, value) { - if (key === "title") { - this.set("name", value); + if (key === 'title') { + this.set('name', value); } } }); - var store = createStore({ + let store = createStore({ tag: Tag }); - run(function() { + let tag = run(() => { tag = store.createRecord('tag', { name: "old" }); - set(tag, "title", "new"); + set(tag, 'title', 'new'); + + return tag; }); - assert.equal(get(tag, "name"), "new", "setUnknownProperty not triggered"); + assert.equal(get(tag, 'name'), 'new', 'setUnknownProperty not triggered'); }); -test("a defaultValue for an attribute can be a function", function(assert) { - var Tag = DS.Model.extend({ +test('a defaultValue for an attribute can be a function', function(assert) { + const Tag = DS.Model.extend({ createdAt: DS.attr('string', { defaultValue() { - return "le default value"; + return 'le default value'; } }) }); - var tag; - var store = createStore({ + let store = createStore({ tag: Tag }); - run(function() { - tag = store.createRecord('tag'); + run(() => { + let tag = store.createRecord('tag'); + assert.equal(get(tag, 'createdAt'), 'le default value', 'the defaultValue function is evaluated'); }); - assert.equal(get(tag, 'createdAt'), "le default value", "the defaultValue function is evaluated"); }); -test("a defaultValue function gets the record, options, and key", function(assert) { +test('a defaultValue function gets the record, options, and key', function(assert) { assert.expect(2); - var Tag = DS.Model.extend({ + const Tag = DS.Model.extend({ createdAt: DS.attr('string', { defaultValue(record, options, key) { - assert.deepEqual(record, tag, "the record is passed in properly"); - assert.equal(key, 'createdAt', "the attribute being defaulted is passed in properly"); - return "le default value"; + assert.deepEqual(record, tag, 'the record is passed in properly'); + assert.equal(key, 'createdAt', 'the attribute being defaulted is passed in properly'); + return 'le default value'; } }) }); - var store = createStore({ + let store = createStore({ tag: Tag }); - var tag; - run(function() { - tag = store.createRecord('tag'); - }); + let tag = run(() => store.createRecord('tag')); get(tag, 'createdAt'); }); -testInDebug("a complex object defaultValue is deprecated ", function(assert) { - var Tag = DS.Model.extend({ +testInDebug('a complex object defaultValue is deprecated', function(assert) { + const Tag = DS.Model.extend({ tagInfo: DS.attr({ defaultValue: [] }) }); - var tag; - var store = createStore({ + let store = createStore({ tag: Tag }); - run(function() { - tag = store.createRecord('tag'); - }); - assert.expectDeprecation(function() { + let tag = run(() => store.createRecord('tag')); + + assert.expectDeprecation(() => { get(tag, 'tagInfo'); }, /Non primitive defaultValues are deprecated/); }); -testInDebug("a null defaultValue is not deprecated", function(assert) { - var Tag = DS.Model.extend({ +testInDebug('a null defaultValue is not deprecated', function(assert) { + const Tag = DS.Model.extend({ tagInfo: DS.attr({ defaultValue: null }) }); - var tag; - var store = createStore({ + let store = createStore({ tag: Tag }); - run(function() { - tag = store.createRecord('tag'); - }); + let tag = run(() => store.createRecord('tag')); + assert.expectNoDeprecation(); assert.equal(get(tag, 'tagInfo'), null); }); -test("setting a property to undefined on a newly created record should not impact the current state", function(assert) { - var Tag = DS.Model.extend({ +test('setting a property to undefined on a newly created record should not impact the current state', function(assert) { + const Tag = DS.Model.extend({ name: DS.attr('string') }); - var store = createStore({ + let store = createStore({ tag: Tag }); - var tag; - - run(function() { + let tag = run(() => { tag = store.createRecord('tag'); + set(tag, 'name', 'testing'); set(tag, 'name', undefined); + + return tag; }); - assert.equal(get(tag, 'currentState.stateName'), "root.loaded.created.uncommitted"); - run(function() { - tag = store.createRecord('tag', { name: undefined }); - }); + assert.equal(get(tag, 'currentState.stateName'), 'root.loaded.created.uncommitted'); - assert.equal(get(tag, 'currentState.stateName'), "root.loaded.created.uncommitted"); + tag = run(() => store.createRecord('tag', { name: undefined })); + + assert.equal(get(tag, 'currentState.stateName'), 'root.loaded.created.uncommitted'); }); // NOTE: this is a 'backdoor' test that ensures internal consistency, and should be // thrown out if/when the current `_attributes` hash logic is removed. -test("setting a property back to its original value removes the property from the `_attributes` hash", function(assert) { +test('setting a property back to its original value removes the property from the `_attributes` hash', function(assert) { assert.expect(3); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { - store.findRecord('person', 1).then(function(person) { - assert.equal(person._internalModel._attributes.name, undefined, "the `_attributes` hash is clean"); + return run(() => { + return store.findRecord('person', 1).then(person => { + assert.equal(person._internalModel._attributes.name, undefined, 'the `_attributes` hash is clean'); - set(person, 'name', "Niceguy Dale"); + set(person, 'name', 'Niceguy Dale'); - assert.equal(person._internalModel._attributes.name, "Niceguy Dale", "the `_attributes` hash contains the changed value"); + assert.equal(person._internalModel._attributes.name, 'Niceguy Dale', 'the `_attributes` hash contains the changed value'); - set(person, 'name', "Scumbag Dale"); + set(person, 'name', 'Scumbag Dale'); - assert.equal(person._internalModel._attributes.name, undefined, "the `_attributes` hash is reset"); + assert.equal(person._internalModel._attributes.name, undefined, 'the `_attributes` hash is reset'); }); }); }); @@ -919,40 +913,40 @@ module("unit/model - with a simple Person model", { store = createStore({ person: Person }); - run(function() { + + run(() => { store.push({ - data: [{ - type: 'person', - id: '1', - attributes: { - name: 'Scumbag Dale' - } - }, { - type: 'person', - id: '2', - attributes: { - name: 'Scumbag Katz' - } - }, { - type: 'person', - id: '3', - attributes: { - name: 'Scumbag Bryn' - } - }] + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'Scumbag Dale' + } + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Scumbag Katz' + } + }, + { + type: 'person', + id: '3', + attributes: { + name: 'Scumbag Bryn' + } + }] }); }); }, afterEach() { - run(function() { - store.destroy(); - Person = null; - store = null; - }); + run(store, 'destroy'); } }); -test("can ask if record with a given id is loaded", function(assert) { +test('can ask if record with a given id is loaded', function(assert) { assert.equal(store.hasRecordForId('person', 1), true, 'should have person with id 1'); assert.equal(store.hasRecordForId('person', 1), true, 'should have person with id 1'); assert.equal(store.hasRecordForId('person', 4), false, 'should not have person with id 4'); @@ -960,73 +954,52 @@ test("can ask if record with a given id is loaded", function(assert) { }); test("a listener can be added to a record", function(assert) { - var count = 0; - var F = function() { count++; }; - var record; + let count = 0; + let F = function() { count++; }; - run(function() { - record = store.createRecord('person'); - }); + let record = run(() => store.createRecord('person')); record.on('event!', F); - run(function() { - record.trigger('event!'); - }); + run(() => record.trigger('event!')); - assert.equal(count, 1, "the event was triggered"); + assert.equal(count, 1, 'the event was triggered'); - run(function() { - record.trigger('event!'); - }); + run(() => record.trigger('event!')); - assert.equal(count, 2, "the event was triggered"); + assert.equal(count, 2, 'the event was triggered'); }); -test("when an event is triggered on a record the method with the same name is invoked with arguments", function(assert) { - var count = 0; - var F = function() { count++; }; - var record; - - run(function() { - record = store.createRecord('person'); - }); +test('when an event is triggered on a record the method with the same name is invoked with arguments', function(assert) { + let count = 0; + let F = function() { count++; }; + let record = run(() => store.createRecord('person')); record.eventNamedMethod = F; - run(function() { - record.trigger('eventNamedMethod'); - }); + run(() => record.trigger('eventNamedMethod')); assert.equal(count, 1, "the corresponding method was called"); }); -test("when a method is invoked from an event with the same name the arguments are passed through", function(assert) { - var eventMethodArgs = null; - var F = function() { - eventMethodArgs = arguments; - }; - var record; - - run(function() { - record = store.createRecord('person'); - }); +test('when a method is invoked from an event with the same name the arguments are passed through', function(assert) { + let eventMethodArgs = null; + let F = function() { eventMethodArgs = arguments; }; + let record = run(() => store.createRecord('person')); record.eventThatTriggersMethod = F; - run(function() { - record.trigger('eventThatTriggersMethod', 1, 2); - }); + run(() => record.trigger('eventThatTriggersMethod', 1, 2)); assert.equal(eventMethodArgs[0], 1); assert.equal(eventMethodArgs[1], 2); }); AssertionPrototype.converts = function converts(type, provided, expected, options = {}) { - var Model = DS.Model.extend({ + const Model = DS.Model.extend({ name: DS.attr(type, options) }); - var registry, container; + let registry, container; if (Ember.Registry) { registry = new Ember.Registry(); container = registry.container(); @@ -1034,13 +1007,18 @@ AssertionPrototype.converts = function converts(type, provided, expected, option container = new Ember.Container(); registry = container; } - var testStore = createStore({ model: Model }); + + let testStore = createStore({ + model: Model + }); run(() => { testStore.push(testStore.normalize('model', { id: 1, name: provided })); testStore.push(testStore.normalize('model', { id: 2 })); - var record = testStore.peekRecord('model', 1); - this.deepEqual(get(record, 'name'), expected, type + " coerces " + provided + " to " + expected); + + let record = testStore.peekRecord('model', 1); + + this.deepEqual(get(record, 'name'), expected, type + ' coerces ' + provided + ' to ' + expected); }); // See: Github issue #421 @@ -1050,11 +1028,11 @@ AssertionPrototype.converts = function converts(type, provided, expected, option }; AssertionPrototype.convertsFromServer = function convertsFromServer(type, provided, expected) { - var Model = DS.Model.extend({ + const Model = DS.Model.extend({ name: DS.attr(type) }); - var registry, container; + let registry, container; if (Ember.Registry) { registry = new Ember.Registry(); container = registry.container(); @@ -1062,61 +1040,66 @@ AssertionPrototype.convertsFromServer = function convertsFromServer(type, provid container = new Ember.Container(); registry = container; } - var testStore = createStore({ + let testStore = createStore({ model: Model, adapter: DS.Adapter.extend({ - shouldBackgroundReloadRecord: () => false + shouldBackgroundReloadRecord() { return false; } }) }); - run(() => { - testStore.push(testStore.normalize('model', { id: "1", name: provided })); - testStore.findRecord('model', 1).then((record) => { - this.deepEqual(get(record, 'name'), expected, type + " coerces " + provided + " to " + expected); + return run(() => { + testStore.push(testStore.normalize('model', { + id: '1', + name: provided + })); + + return testStore.findRecord('model', 1).then(record => { + this.deepEqual(get(record, 'name'), expected, type + ' coerces ' + provided + ' to ' + expected); }); }); }; AssertionPrototype.convertsWhenSet = function(type, provided, expected) { - var Model = DS.Model.extend({ + const Model = DS.Model.extend({ name: DS.attr(type) }); - var testStore = createStore({ + let testStore = createStore({ model: Model, adapter: DS.Adapter.extend({ shouldBackgroundReloadRecord: () => false }) }); - run(() => { + return run(() => { testStore.push({ data: { type: 'model', id: '2' } }); - testStore.findRecord('model', 2).then((record) => { + + return testStore.findRecord('model', 2).then(record => { set(record, 'name', provided); - this.deepEqual(record.serialize().name, expected, type + " saves " + provided + " as " + expected); + this.deepEqual(record.serialize().name, expected, type + ' saves ' + provided + ' as ' + expected); }); }); }; -test("a DS.Model can describe String attributes", function(assert) { +test('a DS.Model can describe String attributes', function(assert) { assert.expect(4); - assert.converts('string', "Scumbag Tom", "Scumbag Tom"); - assert.converts('string', 1, "1"); - assert.converts('string', "", ""); + assert.converts('string', 'Scumbag Tom', 'Scumbag Tom'); + assert.converts('string', 1, '1'); + assert.converts('string', '', ''); assert.converts('string', null, null); }); -test("a DS.Model can describe Number attributes", function(assert) { +test('a DS.Model can describe Number attributes', function(assert) { assert.expect(8); - assert.converts('number', "1", 1); - assert.converts('number', "0", 0); + assert.converts('number', '1', 1); + assert.converts('number', '0', 0); assert.converts('number', 1, 1); assert.converts('number', 0, 0); assert.converts('number', "", null); @@ -1125,8 +1108,8 @@ test("a DS.Model can describe Number attributes", function(assert) { assert.converts('number', false, 0); }); -test("a DS.Model can describe Boolean attributes", function(assert) { - assert.converts('boolean', "1", true); +test('a DS.Model can describe Boolean attributes', function(assert) { + assert.converts('boolean', '1', true); assert.converts('boolean', "", false); assert.converts('boolean', 1, true); assert.converts('boolean', 0, false); @@ -1141,157 +1124,155 @@ test("a DS.Model can describe Boolean attributes", function(assert) { assert.converts('boolean', false, false); }); -test("a DS.Model can describe Date attributes", function(assert) { +test('a DS.Model can describe Date attributes', function(assert) { assert.expect(5); assert.converts('date', null, null); assert.converts('date', undefined, undefined); - var dateString = "2011-12-31T00:08:16.000Z"; - var date = new Date(parseDate(dateString)); + let dateString = '2011-12-31T00:08:16.000Z'; + let date = new Date(parseDate(dateString)); - - var Person = DS.Model.extend({ + const Person = DS.Model.extend({ updatedAt: DS.attr('date') }); - var store = createStore({ + let store = createStore({ person: Person, adapter: DS.Adapter.extend({ - shouldBackgroundReloadRecord: () => false + shouldBackgroundReloadRecord() { return false; } }) }); - run(function() { + return run(() => { store.push({ data: { type: 'person', id: '1' } }); - store.findRecord('person', 1).then(function(record) { - run(function() { - record.set('updatedAt', date); - }); - assert.deepEqual(date, get(record, 'updatedAt'), "setting a date returns the same date"); + + return store.findRecord('person', 1).then(record => { + record.set('updatedAt', date); + assert.deepEqual(date, get(record, 'updatedAt'), 'setting a date returns the same date'); }); + }).then(() => { + assert.convertsFromServer('date', dateString, date); + assert.convertsWhenSet('date', date, dateString); }); - assert.convertsFromServer('date', dateString, date); - assert.convertsWhenSet('date', date, dateString); }); -testInDebug("don't allow setting", function(assert) { - var Person = DS.Model.extend(); - var record; +testInDebug(`don't allow setting`, function(assert) { + const Person = DS.Model.extend(); - var store = createStore({ + let store = createStore({ person: Person }); - run(function() { - record = store.createRecord('person'); - }); + let record = run(() => store.createRecord('person')); - assert.throws(function() { - run(function() { + assert.throws(() => { + run(() => { record.set('isLoaded', true); }); - }, "raised error when trying to set an unsettable record"); + }, 'raised error when trying to set an unsettable record'); }); -test("ensure model exits loading state, materializes data and fulfills promise only after data is available", function(assert) { +test('ensure model exits loading state, materializes data and fulfills promise only after data is available', function(assert) { assert.expect(2); - var store = createStore({ + let store = createStore({ adapter: DS.Adapter.extend({ findRecord(store, type, id, snapshot) { - return Ember.RSVP.resolve({ id: 1, name: "John" }); + return Ember.RSVP.resolve({ + id: 1, + name: 'John' + }); } }), person: Person }); - run(function() { - store.findRecord('person', 1).then(function(person) { + return run(() => { + return store.findRecord('person', 1).then(person => { assert.equal(get(person, 'currentState.stateName'), 'root.loaded.saved', 'model is in loaded state'); assert.equal(get(person, 'isLoaded'), true, 'model is loaded'); }); }); }); -test("A DS.Model can be JSONified", function(assert) { - var Person = DS.Model.extend({ +test('A DS.Model can be JSONified', function(assert) { + const Person = DS.Model.extend({ name: DS.attr('string') }); - var store = createStore({ person: Person }); - var record; + let store = createStore({ person: Person }); + let record = run(() => store.createRecord('person', { name: 'TomHuda' })); - run(function() { - record = store.createRecord('person', { name: "TomHuda" }); - }); - assert.deepEqual(record.toJSON(), { name: "TomHuda" }); + assert.deepEqual(record.toJSON(), { name: 'TomHuda' }); }); -testInDebug("A subclass of DS.Model can not use the `data` property", function(assert) { - var Person = DS.Model.extend({ +testInDebug('A subclass of DS.Model can not use the `data` property', function(assert) { + const Person = DS.Model.extend({ data: DS.attr('string'), name: DS.attr('string') }); - var store = createStore({ person: Person }); + let store = createStore({ person: Person }); - assert.expectAssertion(function() { - run(function() { - store.createRecord('person', { name: "TomHuda" }); + assert.expectAssertion(() => { + run(() => { + store.createRecord('person', { name: 'TomHuda' }); }); }, /`data` is a reserved property name on DS.Model objects/); }); -testInDebug("A subclass of DS.Model can not use the `store` property", function(assert) { - var Retailer = DS.Model.extend({ +testInDebug('A subclass of DS.Model can not use the `store` property', function(assert) { + const Retailer = DS.Model.extend({ store: DS.attr(), name: DS.attr() }); - var store = createStore({ retailer: Retailer }); + let store = createStore({ retailer: Retailer }); - assert.expectAssertion(function() { - run(function() { - store.createRecord('retailer', { name: "Buy n Large" }); + assert.expectAssertion(() => { + run(() => { + store.createRecord('retailer', { name: 'Buy n Large' }); }); }, /`store` is a reserved property name on DS.Model objects/); }); -testInDebug("A subclass of DS.Model can not use reserved properties", function(assert) { +testInDebug('A subclass of DS.Model can not use reserved properties', function(assert) { assert.expect(3); [ 'currentState', 'data', 'store' - ].forEach(function(reservedProperty) { - var invalidExtendObject = {}; + ].forEach(reservedProperty => { + let invalidExtendObject = {}; invalidExtendObject[reservedProperty] = DS.attr(); - var Post = DS.Model.extend(invalidExtendObject); + const Post = DS.Model.extend(invalidExtendObject); - var store = createStore({ post: Post }); + let store = createStore({ post: Post }); - assert.expectAssertion(function() { - run(function() { + assert.expectAssertion(() => { + run(() => { store.createRecord('post', {}); }); }, /is a reserved property name on DS.Model objects/); }); }); -test("Pushing a record into the store should transition it to the loaded state", function(assert) { - var Person = DS.Model.extend({ +test('Pushing a record into the store should transition it to the loaded state', function(assert) { + const Person = DS.Model.extend({ name: DS.attr('string') }); - var store = createStore({ person: Person }); + let store = createStore({ person: Person }); + + run(() => { + let person = store.createRecord('person', { id: 1, name: 'TomHuda' }); - run(function() { - var person = store.createRecord('person', { id: 1, name: 'TomHuda' }); assert.equal(person.get('isNew'), true, 'createRecord should put records into the new state'); + store.push({ data: { type: 'person', @@ -1301,45 +1282,47 @@ test("Pushing a record into the store should transition it to the loaded state", } } }); + assert.equal(person.get('isNew'), false, 'push should put records into the loaded state'); }); }); -testInDebug("A subclass of DS.Model throws an error when calling create() directly", function(assert) { - assert.throws(function() { +testInDebug('A subclass of DS.Model throws an error when calling create() directly', function(assert) { + assert.throws(() => { Person.create(); - }, /You should not call `create` on a model/, "Throws an error when calling create() on model"); + }, /You should not call `create` on a model/, 'Throws an error when calling create() on model'); }); test('toJSON looks up the JSONSerializer using the store instead of using JSONSerializer.create', function(assert) { - var Person = DS.Model.extend({ + const Person = DS.Model.extend({ posts: DS.hasMany('post', { async: false }) }); - var Post = DS.Model.extend({ + const Post = DS.Model.extend({ person: DS.belongsTo('person', { async: false }) }); - var env = setupStore({ + let env = setupStore({ person: Person, post: Post }); - var store = env.store; + let { store } = env; - var person, json; // Loading the person without explicitly // loading its relationships seems to trigger the // original bug where `this.store` was not // present on the serializer due to using .create // instead of `store.serializerFor`. - run(() => { - person = store.push({ + let person = run(() => { + return store.push({ data: { type: 'person', id: '1' } }); }); - var errorThrown = false; + + let errorThrown = false; + let json; try { json = run(person, 'toJSON'); } catch (e) { @@ -1353,36 +1336,36 @@ test('toJSON looks up the JSONSerializer using the store instead of using JSONSe test('accessing attributes in the initializer should not throw an error', function(assert) { assert.expect(1); - var Person = DS.Model.extend({ + + const Person = DS.Model.extend({ name: DS.attr('string'), init() { - this._super.apply(this, arguments); + this._super(...arguments); assert.ok(!this.get('name')); } }); - var env = setupStore({ + let { store } = setupStore({ person: Person }); - var store = env.store; run(() => store.createRecord('person')); }); test('setting the id after model creation should correctly update the id', function(assert) { assert.expect(2); - var Person = DS.Model.extend({ + + const Person = DS.Model.extend({ name: DS.attr('string') }); - var env = setupStore({ + let { store } = setupStore({ person: Person }); - var store = env.store; - run(function () { - var person = store.createRecord('person'); + run(() => { + let person = store.createRecord('person'); assert.equal(person.get('id'), null, 'initial created model id should be null'); @@ -1394,17 +1377,18 @@ test('setting the id after model creation should correctly update the id', funct test('updating the id with store.updateId should correctly when the id property is watched', function(assert) { assert.expect(2); - var Person = DS.Model.extend({ + + const Person = DS.Model.extend({ name: DS.attr('string'), idComputed: Ember.computed('id', function() {}) }); - var env = setupStore({ + let { store } = setupStore({ person: Person }); - var store = env.store; - run(function () { - var person = store.createRecord('person'); + + run(() => { + let person = store.createRecord('person'); person.get('idComputed'); assert.equal(person.get('id'), null, 'initial created model id should be null'); @@ -1417,17 +1401,18 @@ test('updating the id with store.updateId should correctly when the id property test('accessing the model id without the get function should work when id is watched', function(assert) { assert.expect(2); - var Person = DS.Model.extend({ + + const Person = DS.Model.extend({ name: DS.attr('string'), idComputed: Ember.computed('id', function() {}) }); - var env = setupStore({ + let { store } = setupStore({ person: Person }); - var store = env.store; - run(function () { - var person = store.createRecord('person'); + + run(() => { + let person = store.createRecord('person'); person.get('idComputed'); assert.equal(person.get('id'), null, 'initial created model id should be null'); From dd3d3d4e6a34ab0d30af4597d710f1b24dc49055 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:30:39 -0800 Subject: [PATCH 03/25] cleanup test/unit/modules-test.js --- tests/unit/modules-test.js | 58 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/unit/modules-test.js b/tests/unit/modules-test.js index b8a087dbc3c..e25b06233dc 100644 --- a/tests/unit/modules-test.js +++ b/tests/unit/modules-test.js @@ -1,86 +1,86 @@ import { module, test } from 'qunit'; -import Transform from "ember-data/transform"; +import Transform from 'ember-data/transform'; -import Adapter from "ember-data/adapter"; -import JSONAPIAdapter from "ember-data/adapters/json-api"; -import RESTAdapter from "ember-data/adapters/rest"; +import Adapter from 'ember-data/adapter'; +import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import RESTAdapter from 'ember-data/adapters/rest'; -import Store from "ember-data/store"; +import Store from 'ember-data/store'; -import Model from "ember-data/model"; -import attr from "ember-data/attr"; -import { belongsTo, hasMany } from "ember-data/relationships"; +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import { belongsTo, hasMany } from 'ember-data/relationships'; -import Serializer from "ember-data/serializer"; -import JSONSerializer from "ember-data/serializers/json"; -import JSONAPISerializer from "ember-data/serializers/json-api"; -import RESTSerializer from "ember-data/serializers/rest"; -import EmbeddedRecordsMixin from "ember-data/serializers/embedded-records-mixin"; +import Serializer from 'ember-data/serializer'; +import JSONSerializer from 'ember-data/serializers/json'; +import JSONAPISerializer from 'ember-data/serializers/json-api'; +import RESTSerializer from 'ember-data/serializers/rest'; +import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin'; import { AdapterError, InvalidError, TimeoutError, AbortError -} from "ember-data/adapters/errors"; +} from 'ember-data/adapters/errors'; -module("unit/modules - public modules"); +module('unit/modules - public modules'); -test("ember-data/transform", function(assert) { +test('ember-data/transform', function(assert) { assert.ok(Transform); }); -test("ember-data/adapter", function(assert) { +test('ember-data/adapter', function(assert) { assert.ok(Adapter); }); -test("ember-data/adapters/json-api", function(assert) { +test('ember-data/adapters/json-api', function(assert) { assert.ok(JSONAPIAdapter); }); -test("ember-data/adapters/rest", function(assert) { +test('ember-data/adapters/rest', function(assert) { assert.ok(RESTAdapter); }); -test("ember-data/attr", function(assert) { +test('ember-data/attr', function(assert) { assert.ok(attr); }); -test("ember-data/relationships", function(assert) { +test('ember-data/relationships', function(assert) { assert.ok(belongsTo); assert.ok(hasMany); }); -test("ember-data/store", function(assert) { +test('ember-data/store', function(assert) { assert.ok(Store); }); -test("ember-data/model", function(assert) { +test('ember-data/model', function(assert) { assert.ok(Model); }); -test("ember-data/mixins/embedded-records", function(assert) { +test('ember-data/mixins/embedded-records', function(assert) { assert.ok(EmbeddedRecordsMixin); }); -test("ember-data/serializer", function(assert) { +test('ember-data/serializer', function(assert) { assert.ok(Serializer); }); -test("ember-data/serializers/json-api", function(assert) { +test('ember-data/serializers/json-api', function(assert) { assert.ok(JSONAPISerializer); }); -test("ember-data/serializers/json", function(assert) { +test('ember-data/serializers/json', function(assert) { assert.ok(JSONSerializer); }); -test("ember-data/serializers/rest", function(assert) { +test('ember-data/serializers/rest', function(assert) { assert.ok(RESTSerializer); }); -test("ember-data/adapters/errors", function(assert) { +test('ember-data/adapters/errors', function(assert) { assert.ok(AdapterError); assert.ok(InvalidError); assert.ok(TimeoutError); From 9b78843ba7b0094f8439dd782cd9bbcc6a7e4d03 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:30:49 -0800 Subject: [PATCH 04/25] cleanup test/unit/promise-proxies-test.js --- tests/unit/promise-proxies-test.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/unit/promise-proxies-test.js b/tests/unit/promise-proxies-test.js index 5b4e272b302..0c63df1188b 100644 --- a/tests/unit/promise-proxies-test.js +++ b/tests/unit/promise-proxies-test.js @@ -9,23 +9,17 @@ module('PromiseManyArray'); test('.reload should NOT leak the internal promise, rather return another promiseArray', function(assert) { assert.expect(2); - var content = Ember.A(); + let content = Ember.A(); - content.reload = function() { - return Ember.RSVP.Promise.resolve(content); - }; + content.reload = () => Ember.RSVP.Promise.resolve(content); - var array = DS.PromiseManyArray.create({ + let array = DS.PromiseManyArray.create({ content: content }); - Ember.run(function() { - var reloaded = array.reload(); + let reloaded = array.reload(); - assert.ok(reloaded instanceof DS.PromiseManyArray); + assert.ok(reloaded instanceof DS.PromiseManyArray); - reloaded.then(function(value) { - assert.equal(content, value); - }); - }); + return reloaded.then(value => assert.equal(content, value)); }); From db22a0fe9a73a92e420985b51242d38d7216634a Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:31:00 -0800 Subject: [PATCH 05/25] cleanup test/unit/states-test.js --- tests/unit/states-test.js | 123 +++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/tests/unit/states-test.js b/tests/unit/states-test.js index a46274c5524..abfbb1e3c94 100644 --- a/tests/unit/states-test.js +++ b/tests/unit/states-test.js @@ -3,93 +3,92 @@ import QUnit, {module, test} from 'qunit'; import DS from 'ember-data'; const { assert } = QUnit; +const { get } = Ember; -var get = Ember.get; +let rootState, stateName; -var rootState, stateName; - -module("unit/states - Flags for record states", { +module('unit/states - Flags for record states', { beforeEach() { rootState = DS.RootState; } }); assert.flagIsTrue = function flagIsTrue(flag) { - this.equal(get(rootState, stateName + "." + flag), true, stateName + "." + flag + " should be true"); + this.equal(get(rootState, stateName + '.' + flag), true, stateName + '.' + flag + ' should be true'); }; assert.flagIsFalse = function flagIsFalse(flag) { - this.equal(get(rootState, stateName + "." + flag), false, stateName + "." + flag + " should be false"); + this.equal(get(rootState, stateName + '.' + flag), false, stateName + '.' + flag + ' should be false'); }; -test("the empty state", function(assert) { - stateName = "empty"; - assert.flagIsFalse("isLoading"); - assert.flagIsFalse("isLoaded"); - assert.flagIsFalse("isDirty"); - assert.flagIsFalse("isSaving"); - assert.flagIsFalse("isDeleted"); +test('the empty state', function(assert) { + stateName = 'empty'; + assert.flagIsFalse('isLoading'); + assert.flagIsFalse('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); }); -test("the loading state", function(assert) { - stateName = "loading"; - assert.flagIsTrue("isLoading"); - assert.flagIsFalse("isLoaded"); - assert.flagIsFalse("isDirty"); - assert.flagIsFalse("isSaving"); - assert.flagIsFalse("isDeleted"); +test('the loading state', function(assert) { + stateName = 'loading'; + assert.flagIsTrue('isLoading'); + assert.flagIsFalse('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); }); -test("the loaded state", function(assert) { - stateName = "loaded"; - assert.flagIsFalse("isLoading"); - assert.flagIsTrue("isLoaded"); - assert.flagIsFalse("isDirty"); - assert.flagIsFalse("isSaving"); - assert.flagIsFalse("isDeleted"); +test('the loaded state', function(assert) { + stateName = 'loaded'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); }); -test("the updated state", function(assert) { - stateName = "loaded.updated"; - assert.flagIsFalse("isLoading"); - assert.flagIsTrue("isLoaded"); - assert.flagIsTrue("isDirty"); - assert.flagIsFalse("isSaving"); - assert.flagIsFalse("isDeleted"); +test('the updated state', function(assert) { + stateName = 'loaded.updated'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsFalse('isDeleted'); }); -test("the saving state", function(assert) { - stateName = "loaded.updated.inFlight"; - assert.flagIsFalse("isLoading"); - assert.flagIsTrue("isLoaded"); - assert.flagIsTrue("isDirty"); - assert.flagIsTrue("isSaving"); - assert.flagIsFalse("isDeleted"); +test('the saving state', function(assert) { + stateName = 'loaded.updated.inFlight'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsTrue('isSaving'); + assert.flagIsFalse('isDeleted'); }); -test("the deleted state", function(assert) { - stateName = "deleted"; - assert.flagIsFalse("isLoading"); - assert.flagIsTrue("isLoaded"); - assert.flagIsTrue("isDirty"); - assert.flagIsFalse("isSaving"); - assert.flagIsTrue("isDeleted"); +test('the deleted state', function(assert) { + stateName = 'deleted'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsTrue('isDeleted'); }); -test("the deleted.saving state", function(assert) { - stateName = "deleted.inFlight"; - assert.flagIsFalse("isLoading"); - assert.flagIsTrue("isLoaded"); - assert.flagIsTrue("isDirty"); - assert.flagIsTrue("isSaving"); - assert.flagIsTrue("isDeleted"); +test('the deleted.saving state', function(assert) { + stateName = 'deleted.inFlight'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsTrue('isDirty'); + assert.flagIsTrue('isSaving'); + assert.flagIsTrue('isDeleted'); }); -test("the deleted.saved state", function(assert) { - stateName = "deleted.saved"; - assert.flagIsFalse("isLoading"); - assert.flagIsTrue("isLoaded"); - assert.flagIsFalse("isDirty"); - assert.flagIsFalse("isSaving"); - assert.flagIsTrue("isDeleted"); +test('the deleted.saved state', function(assert) { + stateName = 'deleted.saved'; + assert.flagIsFalse('isLoading'); + assert.flagIsTrue('isLoaded'); + assert.flagIsFalse('isDirty'); + assert.flagIsFalse('isSaving'); + assert.flagIsTrue('isDeleted'); }); From e1b894f2ba934265a84be279b890d3682da6ca15 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:31:06 -0800 Subject: [PATCH 06/25] cleanup test/unit/utils-test.js --- tests/unit/utils-test.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/unit/utils-test.js b/tests/unit/utils-test.js index c9bee2a87ff..9dabb38e3dd 100644 --- a/tests/unit/utils-test.js +++ b/tests/unit/utils-test.js @@ -7,12 +7,12 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; import Model from 'ember-data/model'; -import { assertPolymorphicType } from "ember-data/-private/debug"; -import { modelHasAttributeOrRelationshipNamedType } from "ember-data/-private/utils"; +import { assertPolymorphicType } from 'ember-data/-private/debug'; +import { modelHasAttributeOrRelationshipNamedType } from 'ember-data/-private/utils'; -var env, User, Message, Post, Person, Video, Medium; +let env, User, Message, Post, Person, Video, Medium; -module("unit/utils", { +module('unit/utils', { beforeEach() { Person = Model.extend(); User = Model.extend({ @@ -43,10 +43,10 @@ module("unit/utils", { } }); -testInDebug("assertPolymorphicType works for subclasses", function(assert) { - var user, post, person; +testInDebug('assertPolymorphicType works for subclasses', function(assert) { + let user, post, person; - Ember.run(function() { + Ember.run(() => { env.store.push({ data: [{ type: 'user', @@ -70,7 +70,7 @@ testInDebug("assertPolymorphicType works for subclasses", function(assert) { person = env.store.peekRecord('person', 1); }); - var relationship = user.relationshipFor('messages'); + let relationship = user.relationshipFor('messages'); user = user._internalModel; post = post._internalModel; person = person._internalModel; @@ -78,22 +78,22 @@ testInDebug("assertPolymorphicType works for subclasses", function(assert) { try { assertPolymorphicType(user, relationship, post); } catch (e) { - assert.ok(false, "should not throw an error"); + assert.ok(false, 'should not throw an error'); } - assert.expectAssertion(function() { + assert.expectAssertion(() => { assertPolymorphicType(user, relationship, person); }, "You cannot add a record of modelClass 'person' to the 'user.messages' relationship (only 'message' allowed)"); }); -test("modelHasAttributeOrRelationshipNamedType", function(assert) { - var ModelWithTypeAttribute = Model.extend({ +test('modelHasAttributeOrRelationshipNamedType', function(assert) { + let ModelWithTypeAttribute = Model.extend({ type: DS.attr() }); - var ModelWithTypeBelongsTo = Model.extend({ + let ModelWithTypeBelongsTo = Model.extend({ type: DS.belongsTo() }); - var ModelWithTypeHasMany = Model.extend({ + let ModelWithTypeHasMany = Model.extend({ type: DS.hasMany() }); @@ -104,10 +104,10 @@ test("modelHasAttributeOrRelationshipNamedType", function(assert) { assert.equal(modelHasAttributeOrRelationshipNamedType(ModelWithTypeHasMany), true); }); -testInDebug("assertPolymorphicType works for mixins", function(assert) { - var post, video, person; +testInDebug('assertPolymorphicType works for mixins', function(assert) { + let post, video, person; - Ember.run(function() { + Ember.run(() => { env.store.push({ data: [{ type: 'post', @@ -125,7 +125,7 @@ testInDebug("assertPolymorphicType works for mixins", function(assert) { person = env.store.peekRecord('person', 1); }); - var relationship = post.relationshipFor('medias'); + let relationship = post.relationshipFor('medias'); post = post._internalModel; video = video._internalModel; person = person._internalModel; @@ -133,10 +133,10 @@ testInDebug("assertPolymorphicType works for mixins", function(assert) { try { assertPolymorphicType(post, relationship, video); } catch (e) { - assert.ok(false, "should not throw an error"); + assert.ok(false, 'should not throw an error'); } - assert.expectAssertion(function() { + assert.expectAssertion(() => { assertPolymorphicType(post, relationship, person); }, "You cannot add a record of modelClass 'person' to the 'post.medias' relationship (only 'medium' allowed)"); }); From 831a7b6025ecd8661e9a4cd6bb3701ae7f2f3bf5 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:49:16 -0800 Subject: [PATCH 07/25] cleanup tests/unit/transform/string --- tests/unit/transform/string-test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/transform/string-test.js b/tests/unit/transform/string-test.js index 75175e20ae6..713d97f7f64 100644 --- a/tests/unit/transform/string-test.js +++ b/tests/unit/transform/string-test.js @@ -2,24 +2,24 @@ import DS from 'ember-data'; import {module, test} from 'qunit'; -module("unit/transform - DS.StringTransform"); +module('unit/transform - DS.StringTransform'); -test("#serialize", function(assert) { - var transform = new DS.StringTransform(); +test('#serialize', function(assert) { + let transform = new DS.StringTransform(); assert.equal(transform.serialize(null), null); assert.equal(transform.serialize(undefined), null); - assert.equal(transform.serialize("foo"), "foo"); - assert.equal(transform.serialize(1), "1"); + assert.equal(transform.serialize('foo'), 'foo'); + assert.equal(transform.serialize(1), '1'); }); -test("#deserialize", function(assert) { - var transform = new DS.StringTransform(); +test('#deserialize', function(assert) { + let transform = new DS.StringTransform(); assert.equal(transform.deserialize(null), null); assert.equal(transform.deserialize(undefined), null); - assert.equal(transform.deserialize("foo"), "foo"); - assert.equal(transform.deserialize(1), "1"); + assert.equal(transform.deserialize('foo'), 'foo'); + assert.equal(transform.deserialize(1), '1'); }); From dd8a36a4900b4091b95e8d163ff830781261122a Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:49:22 -0800 Subject: [PATCH 08/25] cleanup tests/unit/transform/number --- tests/unit/transform/number-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/transform/number-test.js b/tests/unit/transform/number-test.js index 60ad23db792..17d3e47d381 100644 --- a/tests/unit/transform/number-test.js +++ b/tests/unit/transform/number-test.js @@ -2,10 +2,10 @@ import DS from 'ember-data'; import {module, test} from 'qunit'; -module("unit/transform - DS.NumberTransform"); +module('unit/transform - DS.NumberTransform'); -test("#serialize", function(assert) { - var transform = new DS.NumberTransform(); +test('#serialize', function(assert) { + let transform = new DS.NumberTransform(); assert.equal(transform.serialize(null), null); assert.equal(transform.serialize(undefined), null); @@ -17,12 +17,12 @@ test("#serialize", function(assert) { assert.equal(transform.serialize(-Infinity), null); }); -test("#deserialize", function(assert) { - var transform = new DS.NumberTransform(); +test('#deserialize', function(assert) { + let transform = new DS.NumberTransform(); assert.equal(transform.deserialize(null), null); assert.equal(transform.deserialize(undefined), null); - assert.equal(transform.deserialize("1.1"), 1.1); + assert.equal(transform.deserialize('1.1'), 1.1); assert.equal(transform.deserialize(1.1), 1.1); assert.equal(transform.deserialize(new Number(1.1)), 1.1); assert.equal(transform.deserialize(NaN), null); From 6691164a6efa3e1cf4233071e3a6547750b7d19c Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:49:26 -0800 Subject: [PATCH 09/25] cleanup tests/unit/transform/date --- tests/unit/transform/date-test.js | 41 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tests/unit/transform/date-test.js b/tests/unit/transform/date-test.js index bedd2ef009d..f87823afc23 100644 --- a/tests/unit/transform/date-test.js +++ b/tests/unit/transform/date-test.js @@ -4,27 +4,26 @@ import DS from 'ember-data'; import Ember from 'ember'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import { parseDate } from "ember-data/-private/ext/date"; +import { parseDate } from 'ember-data/-private/ext/date'; -module("unit/transform - DS.DateTransform"); +module('unit/transform - DS.DateTransform'); -var dateString = "2015-01-01T00:00:00.000Z"; -var dateInMillis = parseDate(dateString); -var date = new Date(dateInMillis); -var run = Ember.run; +let dateString = '2015-01-01T00:00:00.000Z'; +let dateInMillis = parseDate(dateString); +let date = new Date(dateInMillis); -test("#serialize", function(assert) { - var transform = new DS.DateTransform(); +test('#serialize', function(assert) { + let transform = new DS.DateTransform(); assert.equal(transform.serialize(null), null); assert.equal(transform.serialize(undefined), null); - assert.equal(transform.serialize(new Date("invalid")), null); + assert.equal(transform.serialize(new Date('invalid')), null); assert.equal(transform.serialize(date), dateString); }); -test("#deserialize", function(assert) { - var transform = new DS.DateTransform(); +test('#deserialize', function(assert) { + let transform = new DS.DateTransform(); // from String assert.equal(transform.deserialize(dateString).toISOString(), dateString); @@ -40,15 +39,15 @@ test("#deserialize", function(assert) { assert.equal(transform.deserialize(undefined), null); }); -test("#deserialize with different offset formats", function(assert) { - var transform = new DS.DateTransform(); - var dateString = '2003-05-24T23:00:00.000+0000'; - var dateStringColon = '2013-03-15T23:22:00.000+00:00'; - var dateStringShortOffset = '2016-12-02T17:30:00.000+00'; +test('#deserialize with different offset formats', function(assert) { + let transform = new DS.DateTransform(); + let dateString = '2003-05-24T23:00:00.000+0000'; + let dateStringColon = '2013-03-15T23:22:00.000+00:00'; + let dateStringShortOffset = '2016-12-02T17:30:00.000+00'; assert.expect(6); - var _dateUTC = Date.UTC; + let _dateUTC = Date.UTC; try { Date.UTC = function () { @@ -65,9 +64,7 @@ test("#deserialize with different offset formats", function(assert) { }); testInDebug('Ember.Date.parse has been deprecated', function(assert) { - run(function() { - assert.expectDeprecation(function() { - Ember.Date.parse(dateString); - }, /Ember.Date.parse is deprecated/); - }); + assert.expectDeprecation(() => { + Ember.Date.parse(dateString); + }, /Ember.Date.parse is deprecated/); }); From 2d29e4a5f3c73ff622c1ca0d5d8d1d0f9b10e98b Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:49:32 -0800 Subject: [PATCH 10/25] cleanup tests/unit/transform/boolean --- tests/unit/transform/boolean-test.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/unit/transform/boolean-test.js b/tests/unit/transform/boolean-test.js index 7f57d5fc52e..4c2ae3c5b40 100644 --- a/tests/unit/transform/boolean-test.js +++ b/tests/unit/transform/boolean-test.js @@ -2,10 +2,10 @@ import DS from 'ember-data'; import {module, test} from 'qunit'; -module("unit/transform - DS.BooleanTransform"); +module('unit/transform - DS.BooleanTransform'); test("#serialize", function(assert) { - var transform = new DS.BooleanTransform(); + let transform = new DS.BooleanTransform(); assert.equal(transform.serialize(null, { allowNull: true }), null); assert.equal(transform.serialize(undefined, { allowNull: true }), null); @@ -20,8 +20,8 @@ test("#serialize", function(assert) { assert.equal(transform.serialize(false), false); }); -test("#deserialize", function(assert) { - var transform = new DS.BooleanTransform(); +test('#deserialize', function(assert) { + let transform = new DS.BooleanTransform(); assert.equal(transform.deserialize(null, { allowNull: true }), null); assert.equal(transform.deserialize(undefined, { allowNull: true }), null); @@ -35,18 +35,18 @@ test("#deserialize", function(assert) { assert.equal(transform.deserialize(true), true); assert.equal(transform.deserialize(false), false); - assert.equal(transform.deserialize("true"), true); - assert.equal(transform.deserialize("TRUE"), true); - assert.equal(transform.deserialize("false"), false); - assert.equal(transform.deserialize("FALSE"), false); + assert.equal(transform.deserialize('true'), true); + assert.equal(transform.deserialize('TRUE'), true); + assert.equal(transform.deserialize('false'), false); + assert.equal(transform.deserialize('FALSE'), false); - assert.equal(transform.deserialize("t"), true); - assert.equal(transform.deserialize("T"), true); - assert.equal(transform.deserialize("f"), false); - assert.equal(transform.deserialize("F"), false); + assert.equal(transform.deserialize('t'), true); + assert.equal(transform.deserialize('T'), true); + assert.equal(transform.deserialize('f'), false); + assert.equal(transform.deserialize('F'), false); - assert.equal(transform.deserialize("1"), true); - assert.equal(transform.deserialize("0"), false); + assert.equal(transform.deserialize('1'), true); + assert.equal(transform.deserialize('0'), false); assert.equal(transform.deserialize(1), true); assert.equal(transform.deserialize(2), false); From f61a2515255415574d42f976c185c5ab55db5386 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:49:40 -0800 Subject: [PATCH 11/25] cleanup tests/unit/transform/unload --- tests/unit/store/unload-test.js | 125 ++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 48 deletions(-) diff --git a/tests/unit/store/unload-test.js b/tests/unit/store/unload-test.js index fc6a4875be6..e13b4e2f02f 100644 --- a/tests/unit/store/unload-test.js +++ b/tests/unit/store/unload-test.js @@ -6,18 +6,22 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var get = Ember.get; -var run = Ember.run; -var store, tryToFind, Record; +const { get, run } = Ember; +let store, tryToFind, Record; -module("unit/store/unload - Store unloading records", { +module('unit/store/unload - Store unloading records', { beforeEach() { Record = DS.Model.extend({ title: DS.attr('string'), wasFetched: DS.attr('boolean') }); - Record.reopenClass({ toString: () => 'Record'}); + + Record.reopenClass({ + toString() { + return 'Record'; + } + }); store = createStore({ adapter: DS.Adapter.extend({ @@ -26,6 +30,7 @@ module("unit/store/unload - Store unloading records", { return Ember.RSVP.resolve({ id: id, wasFetched: true }); } }), + record: Record }); }, @@ -35,10 +40,10 @@ module("unit/store/unload - Store unloading records", { } }); -testInDebug("unload a dirty record asserts", function(assert) { +testInDebug('unload a dirty record asserts', function(assert) { assert.expect(2); - run(function() { + run(() => { store.push({ data: { type: 'record', @@ -50,6 +55,7 @@ testInDebug("unload a dirty record asserts", function(assert) { }); let record = store.peekRecord('record', 1); + record.set('title', 'toto2'); record._internalModel.send('willCommit'); @@ -57,10 +63,10 @@ testInDebug("unload a dirty record asserts", function(assert) { assert.expectAssertion(function() { record.unloadRecord(); - }, "You can only unload a record which is not inFlight. `" + record._internalModel.toString() + "`", "can not unload dirty record"); + }, 'You can only unload a record which is not inFlight. `' + record._internalModel.toString() + '`', 'can not unload dirty record'); // force back into safe to unload mode. - run(function() { + run(() => { record._internalModel.transitionTo('deleted.saved'); }); }); @@ -69,7 +75,7 @@ testInDebug("unload a dirty record asserts", function(assert) { test('unload a record', function(assert) { assert.expect(2); - run(function() { + return run(() => { store.push({ data: { type: 'record', @@ -79,16 +85,16 @@ test('unload a record', function(assert) { } } }); - store.findRecord('record', 1).then(function(record) { - assert.equal(get(record, 'id'), 1, "found record with id 1"); - run(function() { - store.unloadRecord(record); - }); + return store.findRecord('record', 1).then(record => { + assert.equal(get(record, 'id'), 1, 'found record with id 1'); + + run(() => store.unloadRecord(record)); tryToFind = false; - return store.findRecord('record', 1).then(function() { - assert.equal(tryToFind, true, "not found record with id 1"); + + return store.findRecord('record', 1).then(() => { + assert.equal(tryToFind, true, 'not found record with id 1'); }); }); }); @@ -96,31 +102,54 @@ test('unload a record', function(assert) { module("DS.Store - unload record with relationships"); - -test("can commit store after unload record with relationships", function(assert) { +test('can commit store after unload record with relationships', function(assert) { assert.expect(1); - let Brand = DS.Model.extend({ + const Brand = DS.Model.extend({ name: DS.attr('string') }); - Brand.reopenClass({ toString: () => 'Brand'}); - let Product = DS.Model.extend({ + Brand.reopenClass({ + toString() { + return 'Brand'; + } + }); + + const Product = DS.Model.extend({ description: DS.attr('string'), - brand: DS.belongsTo('brand', { async: false }) + brand: DS.belongsTo('brand', { + async: false + }) }); - Product.reopenClass({ toString: () => 'Product'}); - let Like = DS.Model.extend({ - product: DS.belongsTo('product', { async: false }) + Product.reopenClass({ + toString() { + return 'Product'; + } + }); + + const Like = DS.Model.extend({ + product: DS.belongsTo('product', { + async: false + }) + }); + + Like.reopenClass({ + toString() { + return 'Like'; + } }); - Like.reopenClass({ toString: () => 'Like'}); let store = createStore({ adapter: DS.Adapter.extend({ findRecord(store, type, id, snapshot) { - return Ember.RSVP.resolve({ id: 1, description: 'cuisinart', brand: 1 }); + return Ember.RSVP.resolve({ + id: 1, + description: 'cuisinart', + brand: 1 + }); }, + createRecord(store, type, snapshot) { return Ember.RSVP.resolve(); } @@ -132,24 +161,26 @@ test("can commit store after unload record with relationships", function(assert) return run(() => { store.push({ - data: [{ - type: 'brand', - id: '1', - attributes: { - name: 'EmberJS' - } - }, { - type: 'product', - id: '1', - attributes: { - description: 'toto' + data: [ + { + type: 'brand', + id: '1', + attributes: { + name: 'EmberJS' + } }, - relationships: { - brand: { - data: { type: 'brand', id: '1' } + { + type: 'product', + id: '1', + attributes: { + description: 'toto' + }, + relationships: { + brand: { + data: { type: 'brand', id: '1' } + } } - } - }] + }] }); let product = store.peekRecord('product', 1); @@ -157,12 +188,10 @@ test("can commit store after unload record with relationships", function(assert) return like.save(); }).then(() => { - return run(() => { - store.unloadRecord(store.peekRecord('product', 1)); - }); + store.unloadRecord(store.peekRecord('product', 1)); }).then(() => { return store.findRecord('product', 1); - }).then((product) => { + }).then(product => { assert.equal(product.get('description'), 'cuisinart', "The record was unloaded and the adapter's `findRecord` was called"); }); }); From dfa6248a3d37e4cb89b7bb504a4b2b4749023f20 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:49:46 -0800 Subject: [PATCH 12/25] cleanup tests/unit/transform/seralizer-for --- tests/unit/store/serializer-for-test.js | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/unit/store/serializer-for-test.js b/tests/unit/store/serializer-for-test.js index 701e85b3a65..6206ffd4b8c 100644 --- a/tests/unit/store/serializer-for-test.js +++ b/tests/unit/store/serializer-for-test.js @@ -6,10 +6,10 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var container, store, registry, Person; -var run = Ember.run; +let container, store, registry, Person; +const { run } = Ember; -module("unit/store/serializer_for - DS.Store#serializerFor", { +module('unit/store/serializer_for - DS.Store#serializerFor', { beforeEach() { Person = DS.Model.extend({}); var env = setupStore({ person: Person }); @@ -19,35 +19,35 @@ module("unit/store/serializer_for - DS.Store#serializerFor", { }, afterEach() { - run(function() { + run(() => { container.destroy(); store.destroy(); }); } }); -test("Calling serializerFor looks up 'serializer:' from the container", function(assert) { - var PersonSerializer = DS.JSONSerializer.extend(); +test('Calling serializerFor looks up `serializer:` from the container', function(assert) { + const PersonSerializer = DS.JSONSerializer.extend(); registry.register('serializer:person', PersonSerializer); - assert.ok(store.serializerFor('person') instanceof PersonSerializer, "serializer returned from serializerFor is an instance of the registered Serializer class"); + assert.ok(store.serializerFor('person') instanceof PersonSerializer, 'serializer returned from serializerFor is an instance of the registered Serializer class'); }); -test("Calling serializerFor with a type that has not been registered looks up the default ApplicationSerializer", function(assert) { - var ApplicationSerializer = DS.JSONSerializer.extend(); +test('Calling serializerFor with a type that has not been registered looks up the default ApplicationSerializer', function(assert) { + const ApplicationSerializer = DS.JSONSerializer.extend(); registry.register('serializer:application', ApplicationSerializer); - assert.ok(store.serializerFor('person') instanceof ApplicationSerializer, "serializer returned from serializerFor is an instance of ApplicationSerializer"); + assert.ok(store.serializerFor('person') instanceof ApplicationSerializer, 'serializer returned from serializerFor is an instance of ApplicationSerializer'); }); -test("Calling serializerFor with a type that has not been registered and in an application that does not have an ApplicationSerializer looks up the default Ember Data serializer", function(assert) { - assert.ok(store.serializerFor('person') instanceof DS.JSONSerializer, "serializer returned from serializerFor is an instance of DS.JSONSerializer"); +test('Calling serializerFor with a type that has not been registered and in an application that does not have an ApplicationSerializer looks up the default Ember Data serializer', function(assert) { + assert.ok(store.serializerFor('person') instanceof DS.JSONSerializer, 'serializer returned from serializerFor is an instance of DS.JSONSerializer'); }); -testInDebug("Calling serializerFor with a model class should assert", function(assert) { - assert.expectAssertion(function() { +testInDebug('Calling serializerFor with a model class should assert', function(assert) { + assert.expectAssertion(() => { store.serializerFor(Person); }, /Passing classes to store.serializerFor has been removed/); }); From e00e7f6e7fcec028bee65fec1348f1a29fccebcb Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:49:55 -0800 Subject: [PATCH 13/25] cleanup tests/unit/store/seralize --- tests/unit/store/serialize-test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/store/serialize-test.js b/tests/unit/store/serialize-test.js index b90c64a0eea..231f076a81c 100644 --- a/tests/unit/store/serialize-test.js +++ b/tests/unit/store/serialize-test.js @@ -16,7 +16,7 @@ if (isEnabled('ds-deprecate-store-serialize')) { person: Model.extend({ firstName: attr() }) }); - run(function() { + run(() => { let person = store.push({ data: { type: 'person', @@ -26,7 +26,8 @@ if (isEnabled('ds-deprecate-store-serialize')) { } } }); - assert.expectDeprecation("Use of store.serialize is deprecated, use record.serialize instead."); + + assert.expectDeprecation('Use of store.serialize is deprecated, use record.serialize instead.'); store.serialize(person); }); From 501aeec0496a4c4ce8a7fca17c76a541fb50f4ff Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:52:12 -0800 Subject: [PATCH 14/25] cleanup tests/unit/store/unload --- tests/unit/many-array-test.js | 232 +++++++++++++++++--------------- tests/unit/store/unload-test.js | 3 +- 2 files changed, 129 insertions(+), 106 deletions(-) diff --git a/tests/unit/many-array-test.js b/tests/unit/many-array-test.js index 115efadbb04..81aac0bf170 100644 --- a/tests/unit/many-array-test.js +++ b/tests/unit/many-array-test.js @@ -5,165 +5,187 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var env, store; -var attr = DS.attr; -var hasMany = DS.hasMany; -var belongsTo = DS.belongsTo; -var run = Ember.run; +let env, store, Post, Tag; -var Post, Tag; +const { attr, hasMany, belongsTo } = DS; +const { run } = Ember; -module("unit/many_array - DS.ManyArray", { +module('unit/many_array - DS.ManyArray', { beforeEach() { Post = DS.Model.extend({ title: attr('string'), tags: hasMany('tag', { async: false }) }); - Post.reopenClass({ toString: () => 'Post'}); + + Post.reopenClass({ + toString() { + return 'Post'; + } + }); Tag = DS.Model.extend({ name: attr('string'), post: belongsTo('post', { async: false }) }); - Tag.reopenClass({ toString: () => 'Tag'}); + + Tag.reopenClass({ + toString() { + return 'Tag'; + } + }); env = setupStore({ post: Post, tag: Tag }); + store = env.store; }, afterEach() { - run(function() { - store.destroy(); - }); + run(store, 'destroy'); } }); -test("manyArray.save() calls save() on all records", function(assert) { +test('manyArray.save() calls save() on all records', function(assert) { assert.expect(3); - run(function() { - Tag.reopen({ - save() { - assert.ok(true, 'record.save() was called'); - return Ember.RSVP.resolve(); - } - }); + Tag.reopen({ + save() { + assert.ok(true, 'record.save() was called'); + return Ember.RSVP.resolve(); + } + }); + return run(() => { store.push({ - data: [{ - type: 'tag', - id: '1', - attributes: { - name: 'Ember.js' - } - }, { - type: 'tag', - id: '2', - attributes: { - name: 'Tomster' - } - }, { - type: 'post', - id: '3', - attributes: { - title: 'A framework for creating ambitious web applications' + data: [ + { + type: 'tag', + id: '1', + attributes: { + name: 'Ember.js' + } }, - relationships: { - tags: { - data: [ - { type: 'tag', id: '1' }, - { type: 'tag', id: '2' } - ] + { + type: 'tag', + id: '2', + attributes: { + name: 'Tomster' } - } - }] + }, + { + type: 'post', + id: '3', + attributes: { + title: 'A framework for creating ambitious web applications' + }, + relationships: { + tags: { + data: [ + { type: 'tag', id: '1' }, + { type: 'tag', id: '2' } + ] + } + } + }] }); - var post = store.peekRecord('post', 3); - post.get('tags').save().then(function() { + let post = store.peekRecord('post', 3); + + return post.get('tags').save().then(() => { assert.ok(true, 'manyArray.save() promise resolved'); }); }); }); -test("manyArray trigger arrayContentChange functions with the correct values", function(assert) { +test('manyArray trigger arrayContentChange functions with the correct values', function(assert) { assert.expect(6); - var willChangeStartIdx; - var willChangeRemoveAmt; - var willChangeAddAmt; - var originalArrayContentWillChange = DS.ManyArray.prototype.arrayContentWillChange; - var originalArrayContentDidChange = DS.ManyArray.prototype.arrayContentDidChange; + + let willChangeStartIdx; + let willChangeRemoveAmt; + let willChangeAddAmt; + + let originalArrayContentWillChange = DS.ManyArray.prototype.arrayContentWillChange; + let originalArrayContentDidChange = DS.ManyArray.prototype.arrayContentDidChange; DS.ManyArray.reopen({ arrayContentWillChange(startIdx, removeAmt, addAmt) { willChangeStartIdx = startIdx; willChangeRemoveAmt = removeAmt; willChangeAddAmt = addAmt; - return this._super.apply(this, arguments); + + return this._super(...arguments); }, arrayContentDidChange(startIdx, removeAmt, addAmt) { assert.equal(startIdx, willChangeStartIdx, 'WillChange and DidChange startIdx should match'); assert.equal(removeAmt, willChangeRemoveAmt, 'WillChange and DidChange removeAmt should match'); assert.equal(addAmt, willChangeAddAmt, 'WillChange and DidChange addAmt should match'); - return this._super.apply(this, arguments); + + return this._super(...arguments); } }); - run(function() { - store.push({ - data: [{ - type: 'tag', - id: '1', - attributes: { - name: 'Ember.js' - } - }, { - type: 'tag', - id: '2', - attributes: { - name: 'Tomster' - } - }, { - type: 'post', - id: '3', - attributes: { - title: 'A framework for creating ambitious web applications' - }, - relationships: { - tags: { - data: [ - { type: 'tag', id: '1' } - ] - } - } - }] - }); - store.peekRecord('post', 3).get('tags'); - - store.push({ - data: { - type: 'post', - id: '3', - attributes: { - title: 'A framework for creating ambitious web applications' - }, - relationships: { - tags: { - data: [ - { type: 'tag', id: '1' }, - { type: 'tag', id: '2' } - ] + try { + run(() => { + store.push({ + data: [ + { + type: 'tag', + id: '1', + attributes: { + name: 'Ember.js' + } + }, + { + type: 'tag', + id: '2', + attributes: { + name: 'Tomster' + } + }, + { + type: 'post', + id: '3', + attributes: { + title: 'A framework for creating ambitious web applications' + }, + relationships: { + tags: { + data: [ + { type: 'tag', id: '1' } + ] + } + } + } + ] + }); + + store.peekRecord('post', 3).get('tags'); + + store.push({ + data: { + type: 'post', + id: '3', + attributes: { + title: 'A framework for creating ambitious web applications' + }, + relationships: { + tags: { + data: [ + { type: 'tag', id: '1' }, + { type: 'tag', id: '2' } + ] + } } } - } + }); }); - }); - DS.ManyArray.reopen({ - arrayContentWillChange: originalArrayContentWillChange, - arrayContentDidChange: originalArrayContentDidChange - }); + } finally { + DS.ManyArray.reopen({ + arrayContentWillChange: originalArrayContentWillChange, + arrayContentDidChange: originalArrayContentDidChange + }); + } }); diff --git a/tests/unit/store/unload-test.js b/tests/unit/store/unload-test.js index e13b4e2f02f..3e711eca777 100644 --- a/tests/unit/store/unload-test.js +++ b/tests/unit/store/unload-test.js @@ -188,7 +188,8 @@ test('can commit store after unload record with relationships', function(assert) return like.save(); }).then(() => { - store.unloadRecord(store.peekRecord('product', 1)); + // TODO: this is strange, future travelers please address + Ember.run(() => store.unloadRecord(store.peekRecord('product', 1))); }).then(() => { return store.findRecord('product', 1); }).then(product => { From 1103faa02a396484e1b68c420e7892680e722bfe Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:52:16 -0800 Subject: [PATCH 15/25] cleanup tests/unit/store/debug --- tests/unit/debug-test.js | 48 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/tests/unit/debug-test.js b/tests/unit/debug-test.js index 81d828113ea..4a0121fdee5 100644 --- a/tests/unit/debug-test.js +++ b/tests/unit/debug-test.js @@ -5,41 +5,38 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var run = Ember.run; +const { run } = Ember; -var TestAdapter = DS.Adapter.extend(); +const TestAdapter = DS.Adapter.extend(); -module("Debug"); +module('Debug'); -test("_debugInfo groups the attributes and relationships correctly", function(assert) { - var MaritalStatus = DS.Model.extend({ +test('_debugInfo groups the attributes and relationships correctly', function(assert) { + const MaritalStatus = DS.Model.extend({ name: DS.attr('string') }); - var Post = DS.Model.extend({ + const Post = DS.Model.extend({ title: DS.attr('string') }); - var User = DS.Model.extend({ + const User = DS.Model.extend({ name: DS.attr('string'), isDrugAddict: DS.attr('boolean'), maritalStatus: DS.belongsTo('marital-status', { async: false }), posts: DS.hasMany('post', { async: false }) }); - var store = createStore({ + let store = createStore({ adapter: TestAdapter.extend(), maritalStatus: MaritalStatus, post: Post, user: User }); - var record; - run(function() { - record = store.createRecord('user'); - }); + let record = run(() => store.createRecord('user')); - var propertyInfo = record._debugInfo().propertyInfo; + let propertyInfo = record._debugInfo().propertyInfo; assert.equal(propertyInfo.groups.length, 4); assert.deepEqual(propertyInfo.groups[0].properties, ['id', 'name', 'isDrugAddict']); @@ -48,27 +45,27 @@ test("_debugInfo groups the attributes and relationships correctly", function(as }); -test("_debugInfo supports arbitray relationship types", function(assert) { - let MaritalStatus = DS.Model.extend({ +test('_debugInfo supports arbitray relationship types', function(assert) { + const MaritalStatus = DS.Model.extend({ name: DS.attr('string') }); - let Post = DS.Model.extend({ + const Post = DS.Model.extend({ title: DS.attr('string') }); - let User = DS.Model.extend({ + const User = DS.Model.extend({ name: DS.attr('string'), isDrugAddict: DS.attr('boolean'), maritalStatus: DS.belongsTo('marital-status', { async: false }), posts: Ember.computed(() => [1, 2, 3] ) - .readOnly().meta({ - options: { inverse: null }, - isRelationship: true, - kind: 'customRelationship', - name: 'Custom Relationship', - type: 'post' - }) + .readOnly().meta({ + options: { inverse: null }, + isRelationship: true, + kind: 'customRelationship', + name: 'Custom Relationship', + type: 'post' + }) }); let store = createStore({ @@ -125,6 +122,5 @@ test("_debugInfo supports arbitray relationship types", function(assert) { 'maritalStatus', 'posts' ] - } - ) + }) }); From 1813387c1e388f4eb0eaae9f3042006acbec9ef7 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 22:52:23 -0800 Subject: [PATCH 16/25] cleanup tests/unit/adapter-errors --- tests/unit/adapter-errors-test.js | 93 +++++++++++++++++-------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/tests/unit/adapter-errors-test.js b/tests/unit/adapter-errors-test.js index ca275677e33..03198a589a9 100644 --- a/tests/unit/adapter-errors-test.js +++ b/tests/unit/adapter-errors-test.js @@ -1,39 +1,43 @@ import Ember from 'ember'; -import isEnabled from "ember-data/-private/features"; +import isEnabled from 'ember-data/-private/features'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import {module, test} from 'qunit'; import DS from 'ember-data'; -module("unit/adapter-errors - DS.AdapterError"); +module('unit/adapter-errors - DS.AdapterError'); + +test('DS.AdapterError', function(assert) { + let error = new DS.AdapterError(); -test("DS.AdapterError", function(assert) { - var error = new DS.AdapterError(); assert.ok(error instanceof Error); assert.ok(error instanceof Ember.Error); assert.ok(error.isAdapterError); assert.equal(error.message, 'Adapter operation failed'); }); -test("DS.InvalidError", function(assert) { - var error = new DS.InvalidError(); +test('DS.InvalidError', function(assert) { + let error = new DS.InvalidError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'The adapter rejected the commit because it was invalid'); }); -test("DS.TimeoutError", function(assert) { - var error = new DS.TimeoutError(); +test('DS.TimeoutError', function(assert) { + let error = new DS.TimeoutError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'The adapter operation timed out'); }); -test("DS.AbortError", function(assert) { - var error = new DS.AbortError(); +test('DS.AbortError', function(assert) { + let error = new DS.AbortError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); @@ -41,68 +45,75 @@ test("DS.AbortError", function(assert) { }); if (isEnabled('ds-extended-errors')) { - test("DS.UnauthorizedError", function(assert) { - var error = new DS.UnauthorizedError(); + test('DS.UnauthorizedError', function(assert) { + let error = new DS.UnauthorizedError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'The adapter operation is unauthorized'); }); - test("DS.ForbiddenError", function(assert) { - var error = new DS.ForbiddenError(); + test('DS.ForbiddenError', function(assert) { + let error = new DS.ForbiddenError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'The adapter operation is forbidden'); }); - test("DS.NotFoundError", function(assert) { - var error = new DS.NotFoundError(); + test('DS.NotFoundError', function(assert) { + let error = new DS.NotFoundError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'The adapter could not find the resource'); }); - test("DS.ConflictError", function(assert) { - var error = new DS.ConflictError(); + test('DS.ConflictError', function(assert) { + let error = new DS.ConflictError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'The adapter operation failed due to a conflict'); }); - test("DS.ServerError", function(assert) { - var error = new DS.ServerError(); + test('DS.ServerError', function(assert) { + let error = new DS.ServerError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'The adapter operation failed due to a server error'); }); - test("CustomAdapterError", function(assert) { - var CustomAdapterError = DS.AdapterError.extend(); - var error = new CustomAdapterError(); + test('CustomAdapterError', function(assert) { + let CustomAdapterError = DS.AdapterError.extend(); + let error = new CustomAdapterError(); + assert.ok(error instanceof Error); assert.ok(error instanceof DS.AdapterError); assert.ok(error.isAdapterError); assert.equal(error.message, 'Adapter operation failed'); }); - test("CustomAdapterError with default message", function(assert) { - var CustomAdapterError = DS.AdapterError.extend({ message: 'custom error!' }); - var error = new CustomAdapterError(); + test('CustomAdapterError with default message', function(assert) { + let CustomAdapterError = DS.AdapterError.extend({ message: 'custom error!' }); + let error = new CustomAdapterError(); + assert.equal(error.message, 'custom error!'); }); } -var errorsHash = { +const errorsHash = { name: ['is invalid', 'must be a string'], age: ['must be a number'] }; -var errorsArray = [ +const errorsArray = [ { title: 'Invalid Attribute', detail: 'is invalid', @@ -120,11 +131,11 @@ var errorsArray = [ } ]; -var errorsPrimaryHash = { +const errorsPrimaryHash = { base: ['is invalid', 'error message'] }; -var errorsPrimaryArray = [ +const errorsPrimaryArray = [ { title: 'Invalid Document', detail: 'is invalid', @@ -137,23 +148,23 @@ var errorsPrimaryArray = [ } ]; -test("errorsHashToArray", function(assert) { - var result = DS.errorsHashToArray(errorsHash); +test('errorsHashToArray', function(assert) { + let result = DS.errorsHashToArray(errorsHash); assert.deepEqual(result, errorsArray); }); -test("errorsHashToArray for primary data object", function(assert) { - var result = DS.errorsHashToArray(errorsPrimaryHash); +test('errorsHashToArray for primary data object', function(assert) { + let result = DS.errorsHashToArray(errorsPrimaryHash); assert.deepEqual(result, errorsPrimaryArray); }); -test("errorsArrayToHash", function(assert) { - var result = DS.errorsArrayToHash(errorsArray); +test('errorsArrayToHash', function(assert) { + let result = DS.errorsArrayToHash(errorsArray); assert.deepEqual(result, errorsHash); }); -test("errorsArrayToHash without trailing slash", function(assert) { - var result = DS.errorsArrayToHash([ +test('errorsArrayToHash without trailing slash', function(assert) { + let result = DS.errorsArrayToHash([ { detail: 'error message', source: { pointer: 'data/attributes/name' } @@ -162,12 +173,12 @@ test("errorsArrayToHash without trailing slash", function(assert) { assert.deepEqual(result, { name: ['error message'] }); }); -test("errorsArrayToHash for primary data object", function(assert) { - var result = DS.errorsArrayToHash(errorsPrimaryArray); +test('errorsArrayToHash for primary data object', function(assert) { + let result = DS.errorsArrayToHash(errorsPrimaryArray); assert.deepEqual(result, errorsPrimaryHash); }); -testInDebug("DS.InvalidError will normalize errors hash will assert", function(assert) { +testInDebug('DS.InvalidError will normalize errors hash will assert', function(assert) { assert.expectAssertion(function() { new DS.InvalidError({ name: ['is invalid'] }); }, /expects json-api formatted errors/); From 4843b3243a624f4f697963a9eea6203e6113a522 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:25:56 -0800 Subject: [PATCH 17/25] cleanup tests/unit/store/push --- tests/unit/store/push-test.js | 513 ++++++++++++++++++---------------- 1 file changed, 267 insertions(+), 246 deletions(-) diff --git a/tests/unit/store/push-test.js b/tests/unit/store/push-test.js index 040eadf2d4b..b725de1c3d2 100644 --- a/tests/unit/store/push-test.js +++ b/tests/unit/store/push-test.js @@ -8,13 +8,11 @@ import DS from 'ember-data'; import isEnabled from 'ember-data/-private/features'; -var env, store, Person, PhoneNumber, Post; -var attr = DS.attr; -var hasMany = DS.hasMany; -var belongsTo = DS.belongsTo; -var run = Ember.run; +let env, store, Person, PhoneNumber, Post; +const { attr, hasMany, belongsTo } = DS; +const { run } = Ember; -module("unit/store/push - DS.Store#push", { +module('unit/store/push - DS.Store#push', { beforeEach() { Person = DS.Model.extend({ firstName: attr('string'), @@ -43,17 +41,13 @@ module("unit/store/push - DS.Store#push", { }, afterEach() { - run(function() { - store.destroy(); - }); + run(store, 'destroy'); } }); test('Changed attributes are reset when matching data is pushed', function(assert) { - var person; - - run(function() { - person = store.push({ + let person = run(() => { + return store.push({ data: { type: 'person', id: 1, @@ -67,16 +61,14 @@ test('Changed attributes are reset when matching data is pushed', function(asser assert.equal(person.get('firstName'), 'original first name'); assert.equal(person.get('currentState.stateName'), 'root.loaded.saved'); - run(function() { - person.set('firstName', 'updated first name'); - }); + run(() => person.set('firstName', 'updated first name')); assert.equal(person.get('firstName'), 'updated first name'); assert.equal(person.get('lastName'), undefined); assert.equal(person.get('currentState.stateName'), 'root.loaded.updated.uncommitted'); assert.deepEqual(person.changedAttributes().firstName, ['original first name', 'updated first name']); - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -93,12 +85,12 @@ test('Changed attributes are reset when matching data is pushed', function(asser assert.ok(!person.changedAttributes().firstName); }); -test("Calling push with a normalized hash returns a record", function(assert) { +test('Calling push with a normalized hash returns a record', function(assert) { assert.expect(2); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { - var person = store.push({ + return run(() => { + let person = store.push({ data: { type: 'person', id: 'wat', @@ -108,8 +100,9 @@ test("Calling push with a normalized hash returns a record", function(assert) { } } }); - store.findRecord('person', 'wat').then(function(foundPerson) { - assert.equal(foundPerson, person, "record returned via load() is the same as the record returned from findRecord()"); + + return store.findRecord('person', 'wat').then(foundPerson => { + assert.equal(foundPerson, person, 'record returned via load() is the same as the record returned from findRecord()'); assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { id: 'wat', firstName: 'Yehuda', @@ -119,14 +112,14 @@ test("Calling push with a normalized hash returns a record", function(assert) { }); }); -test("Supplying a model class for `push` is the same as supplying a string", function(assert) { +test('Supplying a model class for `push` is the same as supplying a string', function(assert) { assert.expect(1); env.adapter.shouldBackgroundReloadRecord = () => false; - var Programmer = Person.extend(); + const Programmer = Person.extend(); env.registry.register('model:programmer', Programmer); - run(function() { + return run(() => { store.push({ data: { type: 'programmer', @@ -138,7 +131,7 @@ test("Supplying a model class for `push` is the same as supplying a string", fun } }); - store.findRecord('programmer', 'wat').then(function(foundProgrammer) { + return store.findRecord('programmer', 'wat').then(foundProgrammer => { assert.deepEqual(foundProgrammer.getProperties('id', 'firstName', 'lastName'), { id: 'wat', firstName: 'Yehuda', @@ -148,16 +141,23 @@ 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) { +test(`Calling push triggers 'didLoad' even if the record hasn't been requested from the adapter`, function(assert) { assert.expect(1); - Person.reopen({ - didLoad: assert.wait(function() { - assert.ok(true, "The didLoad callback was called"); - }) + let didLoad = new Ember.RSVP.Promise((resolve, reject) => { + Person.reopen({ + didLoad() { + try { + assert.ok(true, 'The didLoad callback was called'); + resolve(); + } catch (e) { + reject(e); + } + } + }); }); - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -169,13 +169,15 @@ test("Calling push triggers `didLoad` even if the record hasn't been requested f } }); }); + + return didLoad; }); -test("Calling push with partial records updates just those attributes", function(assert) { +test('Calling push with partial records updates just those attributes', function(assert) { assert.expect(2); env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { + return run(() => { store.push({ data: { type: 'person', @@ -186,7 +188,8 @@ test("Calling push with partial records updates just those attributes", function } } }); - var person = store.peekRecord('person', 'wat'); + + let person = store.peekRecord('person', 'wat'); store.push({ data: { @@ -198,8 +201,8 @@ test("Calling push with partial records updates just those attributes", function } }); - store.findRecord('person', 'wat').then(function(foundPerson) { - assert.equal(foundPerson, person, "record returned via load() is the same as the record returned from findRecord()"); + return store.findRecord('person', 'wat').then(foundPerson => { + assert.equal(foundPerson, person, 'record returned via load() is the same as the record returned from findRecord()'); assert.deepEqual(foundPerson.getProperties('id', 'firstName', 'lastName'), { id: 'wat', firstName: 'Yehuda', @@ -209,11 +212,11 @@ test("Calling push with partial records updates just those attributes", function }); }); -test("Calling push on normalize allows partial updates with raw JSON", function(assert) { +test('Calling push on normalize allows partial updates with raw JSON', function(assert) { env.registry.register('serializer:person', DS.RESTSerializer); - var person; + let person; - run(function() { + run(() => { person = store.push({ data: { type: 'person', @@ -231,19 +234,22 @@ test("Calling push on normalize allows partial updates with raw JSON", function( })); }); - assert.equal(person.get('firstName'), "Jacquie", "you can push raw JSON into the store"); - assert.equal(person.get('lastName'), "Jackson", "existing fields are untouched"); + assert.equal(person.get('firstName'), 'Jacquie', 'you can push raw JSON into the store'); + assert.equal(person.get('lastName'), 'Jackson', 'existing fields are untouched'); }); -test("Calling push with a normalized hash containing IDs of related records returns a record", function(assert) { +test('Calling push with a normalized hash containing IDs of related records returns a record', function(assert) { assert.expect(1); Person.reopen({ - phoneNumbers: hasMany('phone-number', { async: true }) + phoneNumbers: + hasMany('phone-number', { + async: true + }) }); env.adapter.findRecord = function(store, type, id) { - if (id === "1") { + if (id === '1') { return Ember.RSVP.resolve({ id: 1, number: '5551212', @@ -259,33 +265,36 @@ test("Calling push with a normalized hash containing IDs of related records retu }); } }; - var person; - run(function() { - person = store.push(store.normalize('person', { + return run(() => { + let person = store.push(store.normalize('person', { id: 'wat', firstName: 'John', lastName: 'Smith', phoneNumbers: ["1", "2"] })); - person.get('phoneNumbers').then(function(phoneNumbers) { - assert.deepEqual(phoneNumbers.map(function(item) { + + return person.get('phoneNumbers').then(phoneNumbers => { + assert.deepEqual(phoneNumbers.map(item => { return item.getProperties('id', 'number', 'person'); - }), [{ - id: "1", - number: '5551212', - person: person - }, { - id: "2", - number: '5552121', - person: person - }]); + }), [ + { + id: '1', + number: '5551212', + person: person + }, + { + id: '2', + number: '5552121', + person: person + } + ]); }); }); }); -test("Calling pushPayload allows pushing raw JSON", function(assert) { - run(function() { +test('Calling pushPayload allows pushing raw JSON', function(assert) { + run(() => { store.pushPayload('post', { posts: [{ id: '1', @@ -294,176 +303,184 @@ test("Calling pushPayload allows pushing raw JSON", function(assert) { }); }); - var post = store.peekRecord('post', 1); + let post = store.peekRecord('post', 1); - assert.equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); - run(function() { + run(() => { store.pushPayload('post', { posts: [{ id: '1', - postTitle: "Ember rocks (updated)" + postTitle: 'Ember rocks (updated)' }] }); }); - assert.equal(post.get('postTitle'), "Ember rocks (updated)", "You can update data in the store"); + assert.equal(post.get('postTitle'), 'Ember rocks (updated)', 'You can update data in the store'); }); -test("Calling pushPayload allows pushing singular payload properties", function(assert) { - run(function() { +test('Calling pushPayload allows pushing singular payload properties', function(assert) { + run(() => { store.pushPayload('post', { post: { id: '1', - postTitle: "Ember rocks" + postTitle: 'Ember rocks' } }); }); - var post = store.peekRecord('post', 1); + let post = store.peekRecord('post', 1); - assert.equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); - run(function() { + run(() => { store.pushPayload('post', { post: { id: '1', - postTitle: "Ember rocks (updated)" + postTitle: 'Ember rocks (updated)' } }); }); - assert.equal(post.get('postTitle'), "Ember rocks (updated)", "You can update data in the store"); + assert.equal(post.get('postTitle'), 'Ember rocks (updated)', 'You can update data in the store'); }); -test("Calling pushPayload should use the type's serializer for normalizing", function(assert) { +test(`Calling pushPayload should use the type's serializer for normalizing`, function(assert) { assert.expect(4); + env.registry.register('serializer:post', DS.RESTSerializer.extend({ - normalize(store, payload) { - assert.ok(true, "normalized is called on Post serializer"); - return this._super(store, payload); + normalize() { + assert.ok(true, 'normalized is called on Post serializer'); + return this._super(...arguments); } })); + env.registry.register('serializer:person', DS.RESTSerializer.extend({ - normalize(store, payload) { - assert.ok(true, "normalized is called on Person serializer"); - return this._super(store, payload); + normalize() { + assert.ok(true, 'normalized is called on Person serializer'); + return this._super(...arguments); } })); - run(function() { + run(() => { store.pushPayload('post', { - posts: [{ - id: 1, - postTitle: "Ember rocks" - }], - people: [{ - id: 2, - firstName: "Yehuda" - }] + posts: [ + { + id: 1, + postTitle: 'Ember rocks' + } + ], + people: [ + { + id: 2, + firstName: 'Yehuda' + } + ] }); }); - var post = store.peekRecord('post', 1); + let post = store.peekRecord('post', 1); - assert.equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); - var person = store.peekRecord('person', 2); + let person = store.peekRecord('person', 2); - assert.equal(person.get('firstName'), "Yehuda", "you can push raw JSON into the store"); + assert.equal(person.get('firstName'), 'Yehuda', 'you can push raw JSON into the store'); }); -test("Calling pushPayload without a type uses application serializer's pushPayload method", function(assert) { +test(`Calling pushPayload without a type uses application serializer's pushPayload method`, function(assert) { assert.expect(1); env.registry.register('serializer:application', DS.RESTSerializer.extend({ - pushPayload(store, payload) { - assert.ok(true, "pushPayload is called on Application serializer"); - return this._super(store, payload); + pushPayload() { + assert.ok(true, `pushPayload is called on Application serializer`); + return this._super(...arguments); } })); - run(function() { + run(() => { store.pushPayload({ - posts: [{ id: '1', postTitle: "Ember rocks" }] + posts: [{ id: '1', postTitle: 'Ember rocks' }] }); }); }); -test("Calling pushPayload without a type should use a model's serializer when normalizing", function(assert) { +test(`Calling pushPayload without a type should use a model's serializer when normalizing`, function(assert) { assert.expect(4); env.registry.register('serializer:post', DS.RESTSerializer.extend({ - normalize(store, payload) { - assert.ok(true, "normalized is called on Post serializer"); - return this._super(store, payload); + normalize() { + assert.ok(true, 'normalized is called on Post serializer'); + return this._super(...arguments); } })); env.registry.register('serializer:application', DS.RESTSerializer.extend({ - normalize(store, payload) { - assert.ok(true, "normalized is called on Application serializer"); - return this._super(store, payload); + normalize() { + assert.ok(true, 'normalized is called on Application serializer'); + return this._super(...arguments); } })); - run(function() { + run(() => { store.pushPayload({ - posts: [{ - id: '1', - postTitle: "Ember rocks" - }], - people: [{ - id: '2', - firstName: 'Yehuda' - }] + posts: [ + { + id: '1', + postTitle: 'Ember rocks' + } + ], + people: [ + { + id: '2', + firstName: 'Yehuda' + } + ] }); }); var post = store.peekRecord('post', 1); - assert.equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); + assert.equal(post.get('postTitle'), 'Ember rocks', 'you can push raw JSON into the store'); var person = store.peekRecord('person', 2); - assert.equal(person.get('firstName'), "Yehuda", "you can push raw JSON into the store"); + assert.equal(person.get('firstName'), 'Yehuda', 'you can push raw JSON into the store'); }); -test("Calling pushPayload allows partial updates with raw JSON", function(assert) { +test('Calling pushPayload allows partial updates with raw JSON', function(assert) { env.registry.register('serializer:person', DS.RESTSerializer); - var person; - - run(function() { + run(() => { store.pushPayload('person', { people: [{ id: '1', - firstName: "Robert", - lastName: "Jackson" + firstName: 'Robert', + lastName: 'Jackson' }] }); }); - person = store.peekRecord('person', 1); + let person = store.peekRecord('person', 1); - assert.equal(person.get('firstName'), "Robert", "you can push raw JSON into the store"); - assert.equal(person.get('lastName'), "Jackson", "you can push raw JSON into the store"); + assert.equal(person.get('firstName'), 'Robert', 'you can push raw JSON into the store'); + assert.equal(person.get('lastName'), 'Jackson', 'you can push raw JSON into the store'); - run(function() { + run(() => { store.pushPayload('person', { people: [{ id: '1', - firstName: "Jacquie" + firstName: 'Jacquie' }] }); }); - assert.equal(person.get('firstName'), "Jacquie", "you can push raw JSON into the store"); - assert.equal(person.get('lastName'), "Jackson", "existing fields are untouched"); + assert.equal(person.get('firstName'), 'Jacquie', 'you can push raw JSON into the store'); + assert.equal(person.get('lastName'), 'Jackson', 'existing fields are untouched'); }); test('calling push without data argument as an object raises an error', function(assert) { - var invalidValues = [ + let invalidValues = [ null, 1, 'string', @@ -474,9 +491,9 @@ test('calling push without data argument as an object raises an error', function assert.expect(invalidValues.length); - invalidValues.forEach(function(invalidValue) { - assert.throws(function() { - run(function() { + invalidValues.forEach((invalidValue) => { + assert.throws(() => { + run(() => { store.push('person', invalidValue); }); }, /object/); @@ -488,8 +505,8 @@ testInDebug('Calling push with a link for a non async relationship should warn i phoneNumbers: hasMany('phone-number', { async: false }) }); - assert.expectWarning(function() { - run(function() { + assert.expectWarning(() => { + run(() => { store.push({ data: { type: 'person', @@ -512,8 +529,8 @@ testInDebug('Calling push with a link for a non async relationship should not wa phoneNumbers: hasMany('phone-number', { async: false }) }); - assert.expectNoWarning(function() { - run(function() { + assert.expectNoWarning(() => { + run(() => { store.push({ data: { type: 'person', @@ -536,9 +553,8 @@ testInDebug('Calling push with a link for a non async relationship should not wa }); testInDebug('Calling push with an unknown model name throws an assertion error', function(assert) { - - assert.expectAssertion(function() { - run(function() { + assert.expectAssertion(() => { + run(() => { store.push({ data: { id: '1', @@ -554,7 +570,7 @@ test('Calling push with a link containing an object', function(assert) { phoneNumbers: hasMany('phone-number', { async: true }) }); - run(function() { + run(() => { store.push(store.normalize('person', { id: '1', firstName: 'Tan', @@ -566,13 +582,13 @@ test('Calling push with a link containing an object', function(assert) { })); }); - var person = store.peekRecord('person', 1); + let person = store.peekRecord('person', 1); - assert.equal(person.get('firstName'), "Tan", "you can use links containing an object"); + assert.equal(person.get('firstName'), 'Tan', 'you can use links containing an object'); }); test('Calling push with a link containing the value null', function(assert) { - run(function() { + run(() => { store.push(store.normalize('person', { id: '1', firstName: 'Tan', @@ -582,13 +598,13 @@ test('Calling push with a link containing the value null', function(assert) { })); }); - var person = store.peekRecord('person', 1); + let person = store.peekRecord('person', 1); - assert.equal(person.get('firstName'), "Tan", "you can use links that contain null as a value"); + assert.equal(person.get('firstName'), 'Tan', 'you can use links that contain null as a value'); }); testInDebug('calling push with hasMany relationship the value must be an array', function(assert) { - var invalidValues = [ + let invalidValues = [ 1, 'string', Ember.Object.create(), @@ -598,10 +614,10 @@ testInDebug('calling push with hasMany relationship the value must be an array', assert.expect(invalidValues.length); - invalidValues.forEach(function(invalidValue) { - assert.throws(function() { + invalidValues.forEach(invalidValue => { + assert.throws(() => { try { - run(function () { + run(() => { store.push({ data: { type: 'person', @@ -623,7 +639,7 @@ testInDebug('calling push with hasMany relationship the value must be an array', }); testInDebug('calling push with missing or invalid `id` throws assertion error', function(assert) { - var invalidValues = [ + let invalidValues = [ {}, { id: null }, { id: '' } @@ -631,9 +647,9 @@ testInDebug('calling push with missing or invalid `id` throws assertion error', assert.expect(invalidValues.length); - invalidValues.forEach(function(invalidValue) { - assert.throws(function() { - run(function() { + invalidValues.forEach(invalidValue => { + assert.throws(() => { + run(() => { store.push({ data: invalidValue }); @@ -643,8 +659,8 @@ testInDebug('calling push with missing or invalid `id` throws assertion error', }); testInDebug('calling push with belongsTo relationship the value must not be an array', function(assert) { - assert.throws(function() { - run(function() { + assert.throws(() => { + run(() => { store.push({ data: { type: 'phone-number', @@ -660,12 +676,12 @@ testInDebug('calling push with belongsTo relationship the value must not be an a }, /must not be an array/); }); -testInDebug("Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown attributes", function(assert) { - run(function() { - var originalFlagValue = Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS; +testInDebug('Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown attributes', function(assert) { + run(() => { + let originalFlagValue = Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS; try { Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = true; - assert.expectWarning(function() { + assert.expectWarning(() => { store.push({ data: { type: 'person', @@ -677,19 +693,19 @@ testInDebug("Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown a } } }); - }, "The payload for 'person' contains these unknown attributes: emailAddress,isMascot. Make sure they've been defined in your model."); + }, `The payload for 'person' contains these unknown attributes: emailAddress,isMascot. Make sure they've been defined in your model.`); } finally { Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = originalFlagValue; } }); }); -testInDebug("Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown relationships", function(assert) { - run(function() { +testInDebug('Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown relationships', function(assert) { + run(() => { var originalFlagValue = Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS; try { Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = true; - assert.expectWarning(function() { + assert.expectWarning(() => { store.push({ data: { type: 'person', @@ -701,16 +717,16 @@ testInDebug("Enabling Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS should warn on unknown r } } }); - }, "The payload for 'person' contains these unknown relationships: emailAddresses,mascots. Make sure they've been defined in your model."); + }, `The payload for 'person' contains these unknown relationships: emailAddresses,mascots. Make sure they've been defined in your model.`); } finally { Ember.ENV.DS_WARN_ON_UNKNOWN_KEYS = originalFlagValue; } }); }); -testInDebug("Calling push with unknown keys should not warn by default", function(assert) { - assert.expectNoWarning(function() { - run(function() { +testInDebug('Calling push with unknown keys should not warn by default', function(assert) { + assert.expectNoWarning(() => { + run(() => { store.push({ data: { type: 'person', @@ -730,35 +746,33 @@ if (isEnabled('ds-pushpayload-return')) { test("Calling pushPayload returns records", function(assert) { env.registry.register('serializer:person', DS.RESTSerializer); - var people; - - run(function() { - people = store.pushPayload('person', { + let people = run(() => { + return store.pushPayload('person', { people: [{ id: '1', - firstName: "Robert", - lastName: "Jackson" + firstName: 'Robert', + lastName: 'Jackson' }, { id: '2', - firstName: "Matthew", - lastName: "Beale" + firstName: 'Matthew', + lastName: 'Beale' }] }); }); - assert.equal(people.length, 2, "both records were returned by `store.pushPayload`"); + assert.equal(people.length, 2, 'both records were returned by `store.pushPayload`'); - assert.equal(people[0].get('firstName'), "Robert", "pushPayload returns pushed records"); - assert.equal(people[0].get('lastName'), "Jackson", "pushPayload returns pushed records"); - assert.equal(people[1].get('firstName'), "Matthew", "pushPayload returns pushed records"); - assert.equal(people[1].get('lastName'), "Beale", "pushPayload returns pushed records"); + assert.equal(people[0].get('firstName'), 'Robert', 'pushPayload returns pushed records'); + assert.equal(people[0].get('lastName'), 'Jackson', 'pushPayload returns pushed records'); + assert.equal(people[1].get('firstName'), 'Matthew', 'pushPayload returns pushed records'); + assert.equal(people[1].get('lastName'), 'Beale', 'pushPayload returns pushed records'); }); } -test("_push returns an instance of InternalModel if an object is pushed", function(assert) { +test('_push returns an instance of InternalModel if an object is pushed', function(assert) { let pushResult; - run(function() { + run(() => { pushResult = store._push({ data: { id: 1, @@ -771,11 +785,13 @@ test("_push returns an instance of InternalModel if an object is pushed", functi assert.notOk(pushResult.record, 'InternalModel is not materialized'); }); -test("_push does not require a modelName to resolve to a modelClass", function(assert) { +test('_push does not require a modelName to resolve to a modelClass', function(assert) { let originalCall = store.modelFor; - store.modelFor = () => { assert.notOk('modelFor was triggered as a result of a call to store._push'); }; + store.modelFor = function() { + assert.notOk('modelFor was triggered as a result of a call to store._push'); + }; - run(function() { + run(() => { store._push({ data: { id: 1, @@ -788,10 +804,10 @@ test("_push does not require a modelName to resolve to a modelClass", function(a assert.ok('We made it'); }); -test("_push returns an array of InternalModels if an array is pushed", function(assert) { +test('_push returns an array of InternalModels if an array is pushed', function(assert) { let pushResult; - run(function() { + run(() => { pushResult = store._push({ data: [{ id: 1, @@ -806,10 +822,10 @@ test("_push returns an array of InternalModels if an array is pushed", function( }); -test("_push returns null if no data is pushed", function(assert) { +test('_push returns null if no data is pushed', function(assert) { let pushResult; - run(function() { + run(() => { pushResult = store._push({ data: null }); @@ -818,14 +834,14 @@ test("_push returns null if no data is pushed", function(assert) { assert.strictEqual(pushResult, null); }); -module("unit/store/push - DS.Store#push with JSON-API", { +module('unit/store/push - DS.Store#push with JSON-API', { beforeEach() { - var Person = DS.Model.extend({ + const Person = DS.Model.extend({ name: DS.attr('string'), cars: DS.hasMany('car', { async: false }) }); - var Car = DS.Model.extend({ + const Car = DS.Model.extend({ make: DS.attr('string'), model: DS.attr('string'), person: DS.belongsTo('person', { async: false }) @@ -836,87 +852,92 @@ module("unit/store/push - DS.Store#push with JSON-API", { car: Car, person: Person }); - store = env.store; + store = env.store; }, afterEach() { - run(function() { - store.destroy(); - }); + run(store, 'destroy'); } }); - -test("Should support pushing multiple models into the store", function(assert) { +test('Should support pushing multiple models into the store', function(assert) { assert.expect(2); - run(function() { + run(() => { store.push({ - data: [{ - type: 'person', - id: 1, - attributes: { - name: 'Tom Dale' - } - }, { - type: 'person', - id: 2, - attributes: { - name: "Tomster" - } - }] + data: [ + { + type: 'person', + id: 1, + attributes: { + name: 'Tom Dale' + } + }, + { + type: 'person', + id: 2, + attributes: { + name: "Tomster" + } + }] }); }); - var tom = store.peekRecord('person', 1); + let tom = store.peekRecord('person', 1); assert.equal(tom.get('name'), 'Tom Dale', 'Tom should be in the store'); - var tomster = store.peekRecord('person', 2); + let tomster = store.peekRecord('person', 2); assert.equal(tomster.get('name'), 'Tomster', 'Tomster should be in the store'); }); -test("Should support pushing included models into the store", function(assert) { +test('Should support pushing included models into the store', function(assert) { assert.expect(2); - run(function() { + run(() => { store.push({ - data: [{ - type: 'person', - id: 1, - attributes: { - name: 'Tomster' - }, - relationships: { - cars: [{ - data: { - type: 'person', id: 1 - } - }] + data: [ + { + type: 'person', + id: 1, + attributes: { + name: 'Tomster' + }, + relationships: { + cars: [ + { + data: { + type: 'person', id: 1 + } + } + ] + } } - }], - included: [{ - type: 'car', - id: 1, - attributes: { - make: 'Dodge', - model: 'Neon' - }, - relationships: { - person: { - data: { - id: 1, type: 'person' + ], + included: [ + { + type: 'car', + id: 1, + attributes: { + make: 'Dodge', + model: 'Neon' + }, + relationships: { + person: { + data: { + id: 1, type: 'person' + } } } } - }] + ] }); }); - var tomster = store.peekRecord('person', 1); + let tomster = store.peekRecord('person', 1); assert.equal(tomster.get('name'), 'Tomster', 'Tomster should be in the store'); - var car = store.peekRecord('car', 1); + let car = store.peekRecord('car', 1); assert.equal(car.get('model'), 'Neon', 'Tomster\'s car should be in the store'); }); From 86eb72da440864a9ae2f5b2d3df33b7d600e93d5 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:26:04 -0800 Subject: [PATCH 18/25] cleanup tests/unit/store/peek --- tests/unit/store/peek-record-test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/store/peek-record-test.js b/tests/unit/store/peek-record-test.js index 2c38ed3b86c..490ee94fe00 100644 --- a/tests/unit/store/peek-record-test.js +++ b/tests/unit/store/peek-record-test.js @@ -5,17 +5,17 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var env, store, Person; -var run = Ember.run; +let env, store, Person; +const { run } = Ember; -module("unit/store/peekRecord - Store peekRecord", { +module('unit/store/peekRecord - Store peekRecord', { beforeEach() { - Person = DS.Model.extend(); env = setupStore({ person: Person }); + store = env.store; }, @@ -24,9 +24,9 @@ module("unit/store/peekRecord - Store peekRecord", { } }); -test("peekRecord should return the record if it is in the store ", function(assert) { - run(function() { - var person = store.push({ +test('peekRecord should return the record if it is in the store ', function(assert) { + run(() => { + let person = store.push({ data: { type: 'person', id: '1' @@ -36,8 +36,8 @@ test("peekRecord should return the record if it is in the store ", function(asse }); }); -test("peekRecord should return null if the record is not in the store ", function(assert) { - run(function() { +test('peekRecord should return null if the record is not in the store ', function(assert) { + run(() => { assert.equal(null, store.peekRecord('person', 1), 'peekRecord returns null if the corresponding record is not in the store'); }); }); From 79735f6be035553c3b3b2291efac9b87a286e654 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:26:10 -0800 Subject: [PATCH 19/25] cleanup tests/unit/store/model-for --- tests/unit/store/model-for-test.js | 34 ++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/unit/store/model-for-test.js b/tests/unit/store/model-for-test.js index d6d7130f7ee..6b337200da1 100644 --- a/tests/unit/store/model-for-test.js +++ b/tests/unit/store/model-for-test.js @@ -5,19 +5,16 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var container, store, registry; +let container, store, registry, env; -var camelize = Ember.String.camelize; -var dasherize = Ember.String.dasherize; +const { camelize, dasherize } = Ember.String; +const { run } = Ember; -var run = Ember.run; -var env; - -module("unit/store/model_for - DS.Store#modelFor", { +module('unit/store/model_for - DS.Store#modelFor', { beforeEach() { env = setupStore({ blogPost: DS.Model.extend(), - "blog.post": DS.Model.extend() + 'blog.post': DS.Model.extend() }); store = env.store; container = env.container; @@ -25,32 +22,29 @@ module("unit/store/model_for - DS.Store#modelFor", { }, afterEach() { - run(function() { + run(() => { container.destroy(); store.destroy(); }); } }); -test("when fetching factory from string, sets a normalized key as modelName", function(assert) { - env.replaceContainerNormalize(function(key) { - return dasherize(camelize(key)); - }); +test('when fetching factory from string, sets a normalized key as modelName', function(assert) { + env.replaceContainerNormalize(key => dasherize(camelize(key))); assert.equal(registry.normalize('some.post'), 'some-post', 'precond - container camelizes'); - assert.equal(store.modelFor("blog.post").modelName, "blog.post", "modelName is normalized to dasherized"); + assert.equal(store.modelFor('blog.post').modelName, 'blog.post', 'modelName is normalized to dasherized'); }); -test("when fetching factory from string and dashing normalizer, sets a normalized key as modelName", function(assert) { - env.replaceContainerNormalize(function(key) { - return dasherize(camelize(key)); - }); +test('when fetching factory from string and dashing normalizer, sets a normalized key as modelName', function(assert) { + env.replaceContainerNormalize(key => dasherize(camelize(key))); + assert.equal(registry.normalize('some.post'), 'some-post', 'precond - container dasherizes'); assert.equal(store.modelFor("blog.post").modelName, "blog.post", "modelName is normalized to dasherized"); }); -test("when fetching something that doesn't exist, throws error", function(assert) { - assert.throws(function() { +test(`when fetching something that doesn't exist, throws error`, function(assert) { + assert.throws(() => { store.modelFor('wild-stuff'); }, /No model was found/); }); From 53de21b58d652810e0b1653585479f0f725fbb55 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:26:16 -0800 Subject: [PATCH 20/25] cleanup tests/unit/store/lookup --- tests/unit/store/lookup-test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unit/store/lookup-test.js b/tests/unit/store/lookup-test.js index a8820d59174..b5e7a450ce5 100644 --- a/tests/unit/store/lookup-test.js +++ b/tests/unit/store/lookup-test.js @@ -5,8 +5,8 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var store, env, applicationAdapter, applicationSerializer, Person; -const run = Ember.run; +let store, env, applicationAdapter, applicationSerializer, Person; +const { run } = Ember; function resetStore() { if (store) { @@ -139,4 +139,3 @@ test('serializer lookup order', (assert) => { assert.ok(personSerializer.get('customThingy'), 'uses the person serializer before any fallbacks if it is defined'); }); - From 3ebd3dbe5cf5c157afa5abcb302e1a529a035c81 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:26:23 -0800 Subject: [PATCH 21/25] cleanup tests/unit/store/has-record-for-id --- tests/unit/store/has-record-for-id-test.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/unit/store/has-record-for-id-test.js b/tests/unit/store/has-record-for-id-test.js index 2350f72c176..4d288bf5ae1 100644 --- a/tests/unit/store/has-record-for-id-test.js +++ b/tests/unit/store/has-record-for-id-test.js @@ -5,13 +5,11 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var env, store, Person, PhoneNumber; -var attr = DS.attr; -var hasMany = DS.hasMany; -var belongsTo = DS.belongsTo; -var run = Ember.run; +let env, store, Person, PhoneNumber; +const { attr, hasMany, belongsTo } = DS; +const { run } = Ember; -module("unit/store/hasRecordForId - Store hasRecordForId", { +module('unit/store/hasRecordForId - Store hasRecordForId', { beforeEach() { Person = DS.Model.extend({ @@ -27,7 +25,7 @@ module("unit/store/hasRecordForId - Store hasRecordForId", { env = setupStore({ person: Person, - "phone-number": PhoneNumber + 'phone-number': PhoneNumber }); store = env.store; @@ -39,9 +37,9 @@ module("unit/store/hasRecordForId - Store hasRecordForId", { } }); -test("hasRecordForId should return false for records in the empty state ", function(assert) { +test('hasRecordForId should return false for records in the empty state ', function(assert) { - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -65,8 +63,8 @@ test("hasRecordForId should return false for records in the empty state ", funct }); }); -test("hasRecordForId should return true for records in the loaded state ", function(assert) { - run(function() { +test('hasRecordForId should return true for records in the loaded state ', function(assert) { + run(() => { store.push({ data: { type: 'person', From 8b06cb9ef9c62af519029ba7f0fd4c6efed459c8 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:26:31 -0800 Subject: [PATCH 22/25] cleanup tests/unit/store/asserts --- tests/unit/store/asserts-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/store/asserts-test.js b/tests/unit/store/asserts-test.js index 49c3dd01fa4..5ebaaa5203c 100644 --- a/tests/unit/store/asserts-test.js +++ b/tests/unit/store/asserts-test.js @@ -2,7 +2,7 @@ import {module} from 'qunit'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; import {createStore} from 'dummy/tests/helpers/store'; -module("unit/store/asserts - DS.Store methods produce useful assertion messages"); +module('unit/store/asserts - DS.Store methods produce useful assertion messages'); const MODEL_NAME_METHODS = [ 'createRecord', @@ -23,12 +23,12 @@ const MODEL_NAME_METHODS = [ 'serializerFor' ]; -testInDebug("Calling Store methods with no modelName asserts", function(assert) { +testInDebug('Calling Store methods with no modelName asserts', function(assert) { assert.expect(MODEL_NAME_METHODS.length); let store = createStore(); - MODEL_NAME_METHODS.forEach(function(methodName) { - assert.expectAssertion(function() { + MODEL_NAME_METHODS.forEach(methodName =>{ + assert.expectAssertion(() => { store[methodName](null); }, new RegExp(`You need to pass a model name to the store's ${methodName} method`)); }); From 441198878573d416b9d5ed0bc3c3e36f16a44931 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:26:36 -0800 Subject: [PATCH 23/25] cleanup tests/unit/store/create-record --- tests/unit/store/create-record-test.js | 75 ++++++++++++++------------ 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/tests/unit/store/create-record-test.js b/tests/unit/store/create-record-test.js index 6c9b25bef39..2d6c4014c81 100644 --- a/tests/unit/store/create-record-test.js +++ b/tests/unit/store/create-record-test.js @@ -4,10 +4,10 @@ import Ember from 'ember'; import {module, test} from 'qunit'; import DS from 'ember-data'; -var store, Record, Storage; -var run = Ember.run; +let store, Record, Storage; +const { run } = Ember; -module("unit/store/createRecord - Store creating records", { +module('unit/store/createRecord - Store creating records', { beforeEach() { Record = DS.Model.extend({ title: DS.attr('string') @@ -26,60 +26,65 @@ module("unit/store/createRecord - Store creating records", { } }); -test("doesn't modify passed in properties hash", function(assert) { - var attributes = { foo: 'bar' }; - run(function() { +test(`doesn't modify passed in properties hash`, function(assert) { + let attributes = { foo: 'bar' }; + + run(() => { store.createRecord('record', attributes); store.createRecord('record', attributes); }); - assert.deepEqual(attributes, { foo: 'bar' }, "The properties hash is not modified"); + assert.deepEqual(attributes, { foo: 'bar' }, 'The properties hash is not modified'); }); -test("allow passing relationships as well as attributes", function(assert) { - var records, storage; - run(function() { +test('allow passing relationships as well as attributes', function(assert) { + let records, storage; + + run(() => { store.push({ - data: [{ - type: 'record', - id: '1', - attributes: { - title: "it's a beautiful day" - } - }, { - type: 'record', - id: '2', - attributes: { - title: "it's a beautiful day" + data: [ + { + type: 'record', + id: '1', + attributes: { + title: "it's a beautiful day" + } + }, + { + type: 'record', + id: '2', + attributes: { + title: "it's a beautiful day" + } } - }] + ] }); + records = store.peekAll('record'); storage = store.createRecord('storage', { name: 'Great store', records: records }); }); - 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('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'); }); -module("unit/store/createRecord - Store with models by dash", { +module('unit/store/createRecord - Store with models by dash', { beforeEach() { - var env = setupStore({ - someThing: DS.Model.extend({ foo: DS.attr('string') }) + let env = setupStore({ + someThing: DS.Model.extend({ + foo: DS.attr('string') + }) }); store = env.store; } }); -test("creating a record by dasherize string finds the model", function(assert) { - var attributes = { foo: 'bar' }; - var record; +test('creating a record by dasherize string finds the model', function(assert) { + let attributes = { foo: 'bar' }; - run(function() { - record = store.createRecord('some-thing', attributes); - }); + let record = run(() => store.createRecord('some-thing', attributes)); - assert.equal(record.get('foo'), attributes.foo, "The record is created"); + assert.equal(record.get('foo'), attributes.foo, 'The record is created'); assert.equal(store.modelFor('some-thing').modelName, 'some-thing'); }); From e527d2ffa75e7f0b47cdedb3d2031b8abbd115c6 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Mon, 27 Feb 2017 23:26:43 -0800 Subject: [PATCH 24/25] cleanup tests/unit/store/adapter-interop --- tests/unit/store/adapter-interop-test.js | 162 ++++++++++++----------- 1 file changed, 82 insertions(+), 80 deletions(-) diff --git a/tests/unit/store/adapter-interop-test.js b/tests/unit/store/adapter-interop-test.js index c637c921ec7..e1e251d87b8 100644 --- a/tests/unit/store/adapter-interop-test.js +++ b/tests/unit/store/adapter-interop-test.js @@ -7,27 +7,26 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var get = Ember.get; -var set = Ember.set; -var resolve = Ember.RSVP.resolve; -var TestAdapter, store, person, oldFilterEnabled; -var run = Ember.run; +const { get, set , run } = Ember; +const resolve = Ember.RSVP.resolve; +let TestAdapter, store, person, oldFilterEnabled; -module("unit/store/adapter-interop - DS.Store working with a DS.Adapter", { +module('unit/store/adapter-interop - DS.Store working with a DS.Adapter', { beforeEach() { TestAdapter = DS.Adapter.extend(); oldFilterEnabled = Ember.ENV.ENABLE_DS_FILTER; Ember.ENV.ENABLE_DS_FILTER = false; }, + afterEach() { - run(function() { + run(() => { if (store) { store.destroy(); } Ember.ENV.ENABLE_DS_FILTER = oldFilterEnabled; }); } }); -test("Adapter can be set as a factory", function(assert) { +test('Adapter can be set as a factory', function(assert) { store = createStore({ adapter: TestAdapter }); assert.ok(store.get('defaultAdapter') instanceof TestAdapter); @@ -48,11 +47,11 @@ testInDebug('Adapter can not be set as an instance', function(assert) { assert.expectAssertion(() => store.get('defaultAdapter')); }); -test("Calling Store#find invokes its adapter#find", function(assert) { +test('Calling Store#find invokes its adapter#find', function(assert) { assert.expect(5); - let done = assert.async(); - var adapter = TestAdapter.extend({ + let currentStore; + const Adapter = TestAdapter.extend({ findRecord(store, type, id, snapshot) { assert.ok(true, "Adapter#find was called"); assert.equal(store, currentStore, "Adapter#find was called with the right store"); @@ -60,120 +59,135 @@ 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({ id: 1 }); + return Ember.RSVP.resolve({ + id: 1 + }); } }); - var currentType = DS.Model.extend(); - var currentStore = createStore({ adapter: adapter, test: currentType }); - + const Type = DS.Model.extend(); - run(function() { - currentStore.findRecord('test', 1).finally(done); + currentStore = createStore({ + adapter: Adapter, + test: Type }); + + return run(() => currentStore.findRecord('test', 1)); }); -test("Calling Store#findRecord multiple times coalesces the calls into a adapter#findMany call", function(assert) { +test('Calling Store#findRecord multiple times coalesces the calls into a adapter#findMany call', function(assert) { assert.expect(2); - let done = assert.async(); - var adapter = TestAdapter.extend({ + const Adapter = TestAdapter.extend({ findRecord(store, type, id, snapshot) { - assert.ok(false, "Adapter#findRecord was not called"); + assert.ok(false, 'Adapter#findRecord was not called'); }, findMany(store, type, ids, snapshots) { - assert.ok(true, "Adapter#findMany was called"); - assert.deepEqual(ids, ["1","2"], 'Correct ids were passed in to findMany'); + assert.ok(true, 'Adapter#findMany was called'); + assert.deepEqual(ids, ['1','2'], 'Correct ids were passed in to findMany'); return Ember.RSVP.resolve([{ id: 1 }, { id: 2 }]); }, coalesceFindRequests: true }); - var currentType = DS.Model.extend(); - var currentStore = createStore({ adapter: adapter, test: currentType }); + const Type = DS.Model.extend(); + let store = createStore({ + adapter: Adapter, + test: Type + }); - run(function() { - let promises = [ - currentStore.findRecord('test', 1), - currentStore.findRecord('test', 2) - ]; - Ember.RSVP.all(promises).finally(done); + return run(() => { + return Ember.RSVP.all([ + store.findRecord('test', 1), + store.findRecord('test', 2) + ]); }); }); -test("Returning a promise from `findRecord` asynchronously loads data", function(assert) { +test('Returning a promise from `findRecord` asynchronously loads data', function(assert) { assert.expect(1); - var adapter = TestAdapter.extend({ + const Adapter = TestAdapter.extend({ findRecord(store, type, id, snapshot) { return resolve({ id: 1, name: "Scumbag Dale" }); } }); - var currentType = DS.Model.extend({ + const Type = DS.Model.extend({ name: DS.attr('string') }); - var currentStore = createStore({ adapter: adapter, test: currentType }); - run(function() { - currentStore.findRecord('test', 1).then(assert.wait(function(object) { - assert.strictEqual(get(object, 'name'), "Scumbag Dale", "the data was pushed"); - })); + let store = createStore({ + adapter: Adapter, + test: Type + }); + + return run(() => { + return store.findRecord('test', 1).then(object => { + assert.strictEqual(get(object, 'name'), 'Scumbag Dale', 'the data was pushed'); + }); }); }); -test("IDs provided as numbers are coerced to strings", function(assert) { +test('IDs provided as numbers are coerced to strings', function(assert) { assert.expect(5); - var adapter = TestAdapter.extend({ + const Adapter = TestAdapter.extend({ findRecord(store, type, id, snapshot) { - assert.equal(typeof id, 'string', "id has been normalized to a string"); - return resolve({ id, name: "Scumbag Sylvain" }); + assert.equal(typeof id, 'string', 'id has been normalized to a string'); + return resolve({ id, name: 'Scumbag Sylvain' }); } }); - var currentType = DS.Model.extend({ + const Type = DS.Model.extend({ name: DS.attr('string') }); - var currentStore = createStore({ adapter: adapter, test: currentType }); - run(function() { - currentStore.findRecord('test', 1).then(assert.wait(function(object) { - assert.equal(typeof object.get('id'), 'string', "id was coerced to a string"); - run(function() { - currentStore.push({ + let store = createStore({ + adapter: Adapter, + test: Type + }); + + return run(() => { + return store.findRecord('test', 1).then(object => { + assert.equal(typeof object.get('id'), 'string', 'id was coerced to a string'); + run(() => { + store.push({ data: { type: 'test', id: '2', attributes: { - name: "Scumbag Sam Saffron" + name: 'Scumbag Sam Saffron' } } }); }); - return currentStore.findRecord('test', 2); - })).then(assert.wait(function(object) { - assert.ok(object, "object was found"); - assert.equal(typeof object.get('id'), 'string', "id is a string despite being supplied and searched for as a number"); - })); + + return store.findRecord('test', 2); + }).then(object => { + assert.ok(object, 'object was found'); + assert.equal(typeof object.get('id'), 'string', 'id is a string despite being supplied and searched for as a number'); + }); }); }); -test("can load data for the same record if it is not dirty", function(assert) { +test('can load data for the same record if it is not dirty', function(assert) { assert.expect(3); - var Person = DS.Model.extend({ + const Person = DS.Model.extend({ name: DS.attr('string') }); - var store = createStore({ + let store = createStore({ person: Person, adapter: DS.Adapter.extend({ - shouldBackgroundReloadRecord: () => false + shouldBackgroundReloadRecord() { + return false; + } }) }); - run(function() { + return run(() => { store.push({ data: { type: 'person', @@ -184,37 +198,25 @@ test("can load data for the same record if it is not dirty", function(assert) { } }); - store.findRecord('person', 1).then(assert.wait(function(tom) { - assert.equal(get(tom, 'hasDirtyAttributes'), false, "precond - record is not dirty"); - assert.equal(get(tom, 'name'), "Tom Dale", "returns the correct name"); + return store.findRecord('person', 1).then(tom => { + assert.equal(get(tom, 'hasDirtyAttributes'), false, 'precond - record is not dirty'); + assert.equal(get(tom, 'name'), 'Tom Dale', 'returns the correct name'); store.push({ data: { type: 'person', id: '1', attributes: { - name: "Captain Underpants" + name: 'Captain Underpants' } } }); - assert.equal(get(tom, 'name'), "Captain Underpants", "updated record with new date"); - })); + assert.equal(get(tom, 'name'), 'Captain Underpants', 'updated record with new date'); + }); }); }); -/* -test("DS.Store loads individual records without explicit IDs with a custom primaryKey", function() { - var store = DS.Store.create(); - var Person = DS.Model.extend({ name: DS.attr('string'), primaryKey: 'key' }); - - store.load(Person, { key: 1, name: "Tom Dale" }); - - var tom = store.findRecord(Person, 1); - equal(get(tom, 'name'), "Tom Dale", "the person was successfully loaded for the given ID"); -}); -*/ - -test("loadMany takes an optional Object and passes it on to the Adapter", function(assert) { +test('loadMany takes an optional Object and passes it on to the Adapter', function(assert) { assert.expect(2); var passedQuery = { page: 1 }; From bf59a469233305ed7d365eece81dd728bfe5bea2 Mon Sep 17 00:00:00 2001 From: "David J. Hamilton" Date: Wed, 1 Mar 2017 10:29:26 -0800 Subject: [PATCH 25/25] Consistent cleanup of updateRecord --- tests/unit/model-test.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/unit/model-test.js b/tests/unit/model-test.js index f08e5bbc15f..263c0eae4ca 100644 --- a/tests/unit/model-test.js +++ b/tests/unit/model-test.js @@ -520,12 +520,11 @@ if (isEnabled('ds-rollback-attribute')) { test('Using rollbackAttribute on an in-flight record reverts to the latest in-flight value', function(assert) { assert.expect(4); - let person, finishSaving; - let updateRecordPromise = new Ember.RSVP.Promise(resolve => finishSaving = resolve); + let person; // Make sure the save is async env.adapter.updateRecord = function(store, type, snapshot) { - return updateRecordPromise; + return Ember.RSVP.resolve(); }; return run(() => { @@ -552,8 +551,6 @@ if (isEnabled('ds-rollback-attribute')) { person.rollbackAttribute('name'); assert.equal(person.get('name'), 'Thomas'); - finishSaving(); - return saving; }); });