From a277a1fd014f4b015326f7ab0f199c200f6830f6 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Sun, 2 Jul 2017 14:36:35 -0700 Subject: [PATCH] cleanup --- tests/integration/application-test.js | 69 ++-- .../integration/client-id-generation-test.js | 19 +- tests/integration/inverse-test.js | 13 +- tests/integration/lifecycle-hooks-test.js | 18 +- tests/integration/multiple-stores-test.js | 55 ++-- tests/integration/peek-all-test.js | 15 +- .../polymorphic-belongs-to-test.js | 6 +- .../integration/record-array-manager-test.js | 6 +- tests/integration/record-array-test.js | 5 +- tests/integration/setup-container-test.js | 24 +- tests/integration/snapshot-test.js | 301 +++++++++--------- tests/integration/store-test.js | 216 ++++++------- 12 files changed, 359 insertions(+), 388 deletions(-) diff --git a/tests/integration/application-test.js b/tests/integration/application-test.js index 43316c3bd41..665f14855c4 100644 --- a/tests/integration/application-test.js +++ b/tests/integration/application-test.js @@ -5,13 +5,13 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var run = Ember.run; -var Application = Ember.Application; -var Controller = Ember.Controller; -var Store = DS.Store; -var Namespace = Ember.Namespace; +const run = Ember.run; +const Application = Ember.Application; +const Controller = Ember.Controller; +const Store = DS.Store; +const Namespace = Ember.Namespace; -var app, App, container; +let app, App, container; /* These tests ensure that Ember Data works with Ember.js' application @@ -28,7 +28,7 @@ function lookup(thing) { module("integration/application - Injecting a Custom Store", { beforeEach() { - run(function() { + run(() => { app = Application.create({ StoreService: Store.extend({ isCustom: true }), FooController: Controller.extend(), @@ -48,22 +48,21 @@ module("integration/application - Injecting a Custom Store", { }); test("If a Store property exists on an Ember.Application, it should be instantiated.", function(assert) { - run(function() { + run(() => { assert.ok(getStore().get('isCustom'), "the custom store was instantiated"); }); }); test("If a store is instantiated, it should be made available to each controller.", function(assert) { - var fooController = lookup('controller:foo'); - var isCustom = run(fooController, 'get', 'store.isCustom'); + let fooController = lookup('controller:foo'); + let isCustom = run(fooController, 'get', 'store.isCustom'); assert.ok(isCustom, "the custom store was injected"); }); test("The JSONAPIAdapter is the default adapter when no custom adapter is provided", function(assert) { - run(function() { - var store = getStore(); - - var adapter = store.adapterFor('application'); + run(() => { + let store = getStore(); + let adapter = store.adapterFor('application'); assert.ok(adapter instanceof DS.JSONAPIAdapter, 'default adapter should be the JSONAPIAdapter'); }); @@ -71,7 +70,7 @@ test("The JSONAPIAdapter is the default adapter when no custom adapter is provid module("integration/application - Injecting the Default Store", { beforeEach() { - run(function() { + run(() => { app = Application.create({ FooController: Controller.extend(), BazController: {}, @@ -93,14 +92,14 @@ test("If a Store property exists on an Ember.Application, it should be instantia }); test("If a store is instantiated, it should be made available to each controller.", function(assert) { - run(function() { - var fooController = lookup('controller:foo'); + run(() => { + let fooController = lookup('controller:foo'); assert.ok(fooController.get('store') instanceof DS.Store, "the store was injected"); }); }); test("the DS namespace should be accessible", function(assert) { - run(function() { + run(() => { assert.ok(Namespace.byName('DS') instanceof Namespace, "the DS namespace is accessible"); }); }); @@ -108,7 +107,7 @@ test("the DS namespace should be accessible", function(assert) { if (Ember.inject && Ember.inject.service) { module("integration/application - Using the store as a service", { beforeEach() { - run(function() { + run(() => { app = Application.create({ DoodleService: Ember.Service.extend({ store: Ember.inject.service() }) }); @@ -124,8 +123,8 @@ if (Ember.inject && Ember.inject.service) { }); test("The store can be injected as a service", function(assert) { - run(function() { - var doodleService = lookup('service:doodle'); + run(() => { + let doodleService = lookup('service:doodle'); assert.ok(doodleService.get('store') instanceof Store, "the store can be used as a service"); }); }); @@ -145,14 +144,14 @@ module("integration/application - Attaching initializer", { }); test("ember-data initializer is run", function(assert) { - var ran = false; + let ran = false; App.initializer({ name: "after-ember-data", after: "ember-data", initialize() { ran = true; } }); - run(function() { + run(() => { app = App.create(); }); @@ -161,7 +160,7 @@ test("ember-data initializer is run", function(assert) { test("ember-data initializer does not register the store service when it was already registered", function(assert) { - var AppStore = Store.extend({ + let AppStore = Store.extend({ isCustomStore: true }); @@ -173,26 +172,26 @@ test("ember-data initializer does not register the store service when it was alr } }); - run(function() { + run(() => { app = App.create(); container = app.__container__; }); - var store = getStore(); + let store = getStore(); assert.ok(store && store.get('isCustomStore'), 'ember-data initializer does not overwrite the previous registered service store'); }); testInDebug("store initializer is run (DEPRECATED)", function(assert) { - var ran = false; + let ran = false; App.initializer({ name: "after-store", after: 'store', initialize() { ran = true; } }); - assert.expectDeprecation(function() { - run(function() { + assert.expectDeprecation(() => { + run(() => { app = App.create(); }); }, /The initializer `store` has been deprecated/) @@ -201,15 +200,15 @@ testInDebug("store initializer is run (DEPRECATED)", function(assert) { }); testInDebug("injectStore initializer is run (DEPRECATED)", function(assert) { - var ran = false; + let ran = false; App.initializer({ name: "after-store", after: 'injectStore', initialize() { ran = true; } }); - assert.expectDeprecation(function() { - run(function() { + assert.expectDeprecation(() => { + run(() => { app = App.create(); }); }, /The initializer `injectStore` has been deprecated/) @@ -218,15 +217,15 @@ testInDebug("injectStore initializer is run (DEPRECATED)", function(assert) { }); testInDebug("transforms initializer is run (DEPRECATED)", function(assert) { - var ran = false; + let ran = false; App.initializer({ name: "after-store", after: 'transforms', initialize() { ran = true; } }); - assert.expectDeprecation(function() { - run(function() { + assert.expectDeprecation(() => { + run(() => { app = App.create(); }); }, /The initializer `transforms` has been deprecated/) diff --git a/tests/integration/client-id-generation-test.js b/tests/integration/client-id-generation-test.js index f55d93c95b7..6fe32283f51 100644 --- a/tests/integration/client-id-generation-test.js +++ b/tests/integration/client-id-generation-test.js @@ -5,9 +5,8 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var get = Ember.get; -var Post, Comment, Misc, env; -var run = Ember.run; +const { get, run } = Ember; +let Post, Comment, Misc, env; module("integration/client_id_generation - Client-side ID Generation", { beforeEach() { @@ -38,7 +37,7 @@ module("integration/client_id_generation - Client-side ID Generation", { test("If an adapter implements the `generateIdForRecord` method, the store should be able to assign IDs without saving to the persistence layer.", function(assert) { assert.expect(6); - var idCount = 1; + let idCount = 1; env.adapter.generateIdForRecord = function(passedStore, record) { assert.equal(env.store, passedStore, "store is the first parameter"); @@ -56,7 +55,7 @@ test("If an adapter implements the `generateIdForRecord` method, the store shoul } }; - var comment, post; + let comment, post; run(function() { comment = env.store.createRecord('comment'); post = env.store.createRecord('post'); @@ -75,10 +74,10 @@ test("If an adapter implements the `generateIdForRecord` method, the store shoul test("empty string and undefined ids should coerce to null", function(assert) { assert.expect(6); - var comment, post; - var idCount = 0; + let comment, post; + let idCount = 0; let id = 1; - var ids = [undefined, '']; + let ids = [undefined, '']; env.adapter.generateIdForRecord = function(passedStore, record) { assert.equal(env.store, passedStore, "store is the first parameter"); @@ -90,7 +89,7 @@ test("empty string and undefined ids should coerce to null", function(assert) { return Ember.RSVP.resolve({ data: { id: id++, type: type.modelName } }); }; - run(function() { + run(() => { comment = env.store.createRecord('misc'); post = env.store.createRecord('misc'); }); @@ -100,7 +99,7 @@ test("empty string and undefined ids should coerce to null", function(assert) { // Despite client-generated IDs, calling commit() on the store should still // invoke the adapter's `createRecord` method. - run(function() { + run(() => { comment.save(); post.save(); }); diff --git a/tests/integration/inverse-test.js b/tests/integration/inverse-test.js index a584b3f7c37..c48bb75eb7a 100644 --- a/tests/integration/inverse-test.js +++ b/tests/integration/inverse-test.js @@ -6,11 +6,10 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var env, store, User, Job, ReflexiveModel; +let env, store, User, Job, ReflexiveModel; -var attr = DS.attr; -var belongsTo = DS.belongsTo; -var run = Ember.run; +const { attr, belongsTo } = DS; +const { run } = Ember; function stringify(string) { return function() { return string; }; @@ -109,7 +108,7 @@ testInDebug("Errors out if you define 2 inverses to the same model", function(as job: belongsTo('job', { async: false }) }); - assert.expectAssertion(function() { + assert.expectAssertion(() => { User.inverseFor('job', store); }, "You defined the 'job' relationship on user, but you defined the inverse relationships of type job multiple times. Look at https://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses"); }); @@ -129,9 +128,9 @@ test("Caches findInverseFor return value", function(assert) { testInDebug("Errors out if you do not define an inverse for a reflexive relationship", function(assert) { //Maybe store is evaluated lazily, so we need this :( - assert.expectWarning(function() { + assert.expectWarning(() => { var reflexiveModel; - run(function() { + run(() => { store.push({ data: { type: 'reflexive-model', diff --git a/tests/integration/lifecycle-hooks-test.js b/tests/integration/lifecycle-hooks-test.js index 69f06b8143b..d74ae1146c6 100644 --- a/tests/integration/lifecycle-hooks-test.js +++ b/tests/integration/lifecycle-hooks-test.js @@ -5,10 +5,10 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var Person, env; -var attr = DS.attr; -var resolve = Ember.RSVP.resolve; -var run = Ember.run; +let Person, env; +const { attr } = DS; +const { run } = Ember; +const { resolve } = Ember.RSVP; module("integration/lifecycle_hooks - Lifecycle Hooks", { beforeEach() { @@ -33,11 +33,8 @@ test("When the adapter acknowledges that a record has been created, a `didCreate env.adapter.createRecord = function(store, type, snapshot) { return resolve({ data: { id: 99, type: "person", attributes: { name: "Yehuda Katz" } } }); }; - var person; - run(function() { - person = env.store.createRecord('person', { name: "Yehuda Katz" }); - }); + let person = run(() => env.store.createRecord('person', { name: "Yehuda Katz" })); person.on('didCreate', function() { assert.equal(this, person, "this is bound to the record"); @@ -55,11 +52,8 @@ test("When the adapter acknowledges that a record has been created without a new env.adapter.createRecord = function(store, type, snapshot) { return Ember.RSVP.resolve(); }; - var person; - run(function() { - person = env.store.createRecord('person', { id: 99, name: "Yehuda Katz" }); - }); + let person = run(() => env.store.createRecord('person', { id: 99, name: "Yehuda Katz" })); person.on('didCreate', function() { assert.equal(this, person, "this is bound to the record"); diff --git a/tests/integration/multiple-stores-test.js b/tests/integration/multiple-stores-test.js index c7708821b92..4edd341eb10 100644 --- a/tests/integration/multiple-stores-test.js +++ b/tests/integration/multiple-stores-test.js @@ -4,9 +4,9 @@ import { module, test } from 'qunit'; import DS from 'ember-data'; -var env; -var SuperVillain, HomePlanet, EvilMinion; -var run = Ember.run; +let env; +let SuperVillain, HomePlanet, EvilMinion; +const { run } = Ember; module("integration/multiple_stores - Multiple Stores Tests", { setup() { @@ -51,28 +51,26 @@ test("should be able to push into multiple stores", function(assert) { shouldBackgroundReloadRecord: () => false })); - var home_planet_main = { id: '1', name: 'Earth' }; - var home_planet_a = { id: '1', name: 'Mars' }; - var home_planet_b = { id: '1', name: 'Saturn' }; + let home_planet_main = { id: '1', name: 'Earth' }; + let home_planet_a = { id: '1', name: 'Mars' }; + let home_planet_b = { id: '1', name: 'Saturn' }; - run(function() { + run(() => { env.store.push(env.store.normalize('home-planet', home_planet_main)); env.store_a.push(env.store_a.normalize('home-planet', home_planet_a)); env.store_b.push(env.store_b.normalize('home-planet', home_planet_b)); }); - run(env.store, 'findRecord', 'home-planet', 1).then(assert.wait(function(homePlanet) { - assert.equal(homePlanet.get('name'), "Earth"); - })); - - run(env.store_a, 'findRecord', 'home-planet', 1).then(assert.wait(function(homePlanet) { - assert.equal(homePlanet.get('name'), "Mars"); - })); - - run(env.store_b, 'findRecord', 'home-planet', 1).then(assert.wait(function(homePlanet) { - assert.equal(homePlanet.get('name'), "Saturn"); - })); + return env.store.findRecord('home-planet', 1).then(homePlanet => { + assert.equal(homePlanet.get('name'), 'Earth'); + return env.store_a.findRecord('homePlanet', 1); + }).then(homePlanet => { + assert.equal(homePlanet.get('name'), 'Mars'); + return env.store_b.findRecord('homePlanet', 1); + }).then(homePlanet => { + assert.equal(homePlanet.get('name'), 'Saturn'); + }); }); test("embedded records should be created in multiple stores", function(assert) { @@ -82,11 +80,11 @@ test("embedded records should be created in multiple stores", function(assert) { } })); - var serializer_main = env.store.serializerFor('home-planet'); - var serializer_a = env.store_a.serializerFor('home-planet'); - var serializer_b = env.store_b.serializerFor('home-planet'); + let serializer_main = env.store.serializerFor('home-planet'); + let serializer_a = env.store_a.serializerFor('home-planet'); + let serializer_b = env.store_b.serializerFor('home-planet'); - var json_hash_main = { + let json_hash_main = { homePlanet: { id: "1", name: "Earth", @@ -97,7 +95,7 @@ test("embedded records should be created in multiple stores", function(assert) { }] } }; - var json_hash_a = { + let json_hash_a = { homePlanet: { id: "1", name: "Mars", @@ -108,7 +106,7 @@ test("embedded records should be created in multiple stores", function(assert) { }] } }; - var json_hash_b = { + let json_hash_b = { homePlanet: { id: "1", name: "Saturn", @@ -119,24 +117,23 @@ test("embedded records should be created in multiple stores", function(assert) { }] } }; - var json_main, json_a, json_b; + let json_main, json_a, json_b; - run(function() { + run(() => { json_main = serializer_main.normalizeResponse(env.store, env.store.modelFor('home-planet'), json_hash_main, 1, 'findRecord'); env.store.push(json_main); assert.equal(env.store.hasRecordForId('super-villain', "1"), true, "superVillain should exist in service:store"); }); - run(function() { + run(() => { json_a = serializer_a.normalizeResponse(env.store_a, env.store_a.modelFor('home-planet'), json_hash_a, 1, 'findRecord'); env.store_a.push(json_a); assert.equal(env.store_a.hasRecordForId("super-villain", "1"), true, "superVillain should exist in store:store-a"); }); - run(function() { + run(() => { json_b = serializer_b.normalizeResponse(env.store_b, env.store_a.modelFor('home-planet'), json_hash_b, 1, 'findRecord'); env.store_b.push(json_b); assert.equal(env.store_b.hasRecordForId("super-villain", "1"), true, "superVillain should exist in store:store-b"); }); - }); diff --git a/tests/integration/peek-all-test.js b/tests/integration/peek-all-test.js index b505d0a8a2e..2f836487f2c 100644 --- a/tests/integration/peek-all-test.js +++ b/tests/integration/peek-all-test.js @@ -5,10 +5,9 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var get = Ember.get; -var run = Ember.run; +const { get, run } = Ember; -var Person, store, array, moreArray; +let Person, store, array, moreArray; module("integration/peek-all - DS.Store#peekAll()", { beforeEach() { @@ -49,14 +48,14 @@ module("integration/peek-all - DS.Store#peekAll()", { }); test("store.peekAll('person') should return all records and should update with new ones", function(assert) { - run(function() { + run(() => { store.push(array); }); - var all = store.peekAll('person'); + let all = store.peekAll('person'); assert.equal(get(all, 'length'), 2); - run(function() { + run(() => { store.push(moreArray); }); @@ -66,7 +65,7 @@ test("store.peekAll('person') should return all records and should update with n test("Calling store.peekAll() multiple times should update immediately inside the runloop", function(assert) { assert.expect(3); - Ember.run(function() { + Ember.run(() => { assert.equal(get(store.peekAll('person'), 'length'), 0, 'should initially be empty'); store.createRecord('person', { name: "Tomster" }); assert.equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); @@ -86,7 +85,7 @@ test("Calling store.peekAll() multiple times should update immediately inside th test("Calling store.peekAll() after creating a record should return correct data", function(assert) { assert.expect(1); - Ember.run(function() { + Ember.run(() => { store.createRecord('person', { name: "Tomster" }); assert.equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); }); diff --git a/tests/integration/polymorphic-belongs-to-test.js b/tests/integration/polymorphic-belongs-to-test.js index 96ccd3a431c..fc1822d96a7 100644 --- a/tests/integration/polymorphic-belongs-to-test.js +++ b/tests/integration/polymorphic-belongs-to-test.js @@ -130,13 +130,11 @@ test('using store.push with a null value for a payload in relationships sets the } }; - let done = assert.async(); - book.get('author').then((author) => { + return book.get('author').then(author => { assert.equal(author.get('id'), 1); run(() => store.push(payloadThatResetsBelongToRelationship)); return book.get('author'); - }).then((author) => { + }).then(author => { assert.equal(author, null); - done(); }); }); diff --git a/tests/integration/record-array-manager-test.js b/tests/integration/record-array-manager-test.js index 83975e5a1e6..8e921f1d1a6 100644 --- a/tests/integration/record-array-manager-test.js +++ b/tests/integration/record-array-manager-test.js @@ -35,12 +35,12 @@ module('integration/record_array_manager', { }); function tap(obj, methodName, callback) { - var old = obj[methodName]; + let old = obj[methodName]; - var summary = { called: [] }; + let summary = { called: [] }; obj[methodName] = function() { - var result = old.apply(obj, arguments); + let result = old.apply(obj, arguments); if (callback) { callback.apply(obj, arguments); } diff --git a/tests/integration/record-array-test.js b/tests/integration/record-array-test.js index ed45e4e21d5..e784365e397 100644 --- a/tests/integration/record-array-test.js +++ b/tests/integration/record-array-test.js @@ -271,14 +271,13 @@ test('a loaded record is not removed from a record array when it is deleted even scumbag.deleteRecord(); }); - run(function() { + run(() => { assert.equal(tag.get('people.length'), 1, 'record is not removed from the record array'); assert.equal(tag.get('people').objectAt(0), scumbag, 'tag still has the scumbag'); }); }); test("a loaded record is not removed from both the record array and from the belongs to, even if the belongsTo side isn't defined", function(assert) { - let env = setupStore({ tag: Tag, person: Person, @@ -326,7 +325,7 @@ test("a loaded record is not removed from both the record array and from the bel tool = store.peekRecord('tool', 1); }); - run(function() { + run(() => { assert.equal(tag.get('people.length'), 1, 'record is in the record array'); assert.equal(tool.get('person'), scumbag, 'the tool belongs to the record'); }); diff --git a/tests/integration/setup-container-test.js b/tests/integration/setup-container-test.js index 6fabea2a7fe..eaaf937e554 100644 --- a/tests/integration/setup-container-test.js +++ b/tests/integration/setup-container-test.js @@ -4,12 +4,10 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var run = Ember.run; -var Store = DS.Store; -var EmberObject = Ember.Object; -var setupContainer = DS._setupContainer; +const { run, Object: EmberObject } = Ember; +const { Store, _setupContainer: setupContainer } = DS; -var container, registry, application; +let container, registry, application; /* These tests ensure that Ember Data works with Ember.js' container @@ -18,14 +16,12 @@ var container, registry, application; module("integration/setup-container - Setting up a container", { beforeEach() { - run(function() { - application = Ember.Application.create(); - }); + application = run(() => Ember.Application.create()); container = application.__container__; registry = application.__registry__; - var setupContainerArgument; + let setupContainerArgument; if (registry) { setupContainerArgument = application; } else { @@ -37,9 +33,7 @@ module("integration/setup-container - Setting up a container", { }, afterEach() { - run(function() { - application.destroy(); - }); + run(() => application.destroy()); } }); @@ -53,19 +47,19 @@ test("The store should be registered into the container as a service.", function test("If a store is instantiated, it should be made available to each controller.", function(assert) { registry.register('controller:foo', EmberObject.extend({})); - var fooController = container.lookup('controller:foo'); + let fooController = container.lookup('controller:foo'); assert.ok(fooController.get('store') instanceof Store, "the store was injected"); }); test("serializers are not returned as singletons - each lookup should return a different instance", function(assert) { - var serializer1, serializer2; + let serializer1, serializer2; serializer1 = container.lookup('serializer:-rest'); serializer2 = container.lookup('serializer:-rest'); assert.notEqual(serializer1, serializer2); }); test("adapters are not returned as singletons - each lookup should return a different instance", function(assert) { - var adapter1, adapter2; + let adapter1, adapter2; adapter1 = container.lookup('adapter:-rest'); adapter2 = container.lookup('adapter:-rest'); assert.notEqual(adapter1, adapter2); diff --git a/tests/integration/snapshot-test.js b/tests/integration/snapshot-test.js index cf125d7d797..992907ef007 100644 --- a/tests/integration/snapshot-test.js +++ b/tests/integration/snapshot-test.js @@ -5,8 +5,8 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var run = Ember.run; -var env, Post, Comment; +const { run } = Ember; +let env, Post, Comment; module("integration/snapshot - DS.Snapshot", { beforeEach() { @@ -27,7 +27,7 @@ module("integration/snapshot - DS.Snapshot", { }, afterEach() { - run(function() { + run(() => { env.store.destroy(); }); } @@ -36,7 +36,7 @@ module("integration/snapshot - DS.Snapshot", { test("record._createSnapshot() returns a snapshot", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -46,8 +46,8 @@ test("record._createSnapshot() returns a snapshot", function(assert) { } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); assert.ok(snapshot instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); }); @@ -56,7 +56,7 @@ test("record._createSnapshot() returns a snapshot", function(assert) { test("snapshot.id, snapshot.type and snapshot.modelName returns correctly", function(assert) { assert.expect(3); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -66,8 +66,8 @@ test("snapshot.id, snapshot.type and snapshot.modelName returns correctly", func } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); assert.equal(snapshot.id, '1', 'id is correct'); assert.ok(DS.Model.detect(snapshot.type), 'type is correct'); @@ -87,7 +87,7 @@ test('snapshot.type loads the class lazily', function(assert) { return modelFor.call(env.store, name); }; - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -109,7 +109,7 @@ test('snapshot.type loads the class lazily', function(assert) { test("snapshot.attr() does not change when record changes", function(assert) { assert.expect(2); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -119,8 +119,8 @@ test("snapshot.attr() does not change when record changes", function(assert) { } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); assert.equal(snapshot.attr('title'), 'Hello World', 'snapshot title is correct'); post.set('title', 'Tomster'); @@ -131,7 +131,7 @@ test("snapshot.attr() does not change when record changes", function(assert) { test("snapshot.attr() throws an error attribute not found", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -141,10 +141,10 @@ test("snapshot.attr() throws an error attribute not found", function(assert) { } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); - assert.throws(function() { + assert.throws(() => { snapshot.attr('unknown'); }, /has no attribute named 'unknown' defined/, 'attr throws error'); }); @@ -153,7 +153,7 @@ test("snapshot.attr() throws an error attribute not found", function(assert) { test("snapshot.attributes() returns a copy of all attributes for the current snapshot", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -163,10 +163,10 @@ test("snapshot.attributes() returns a copy of all attributes for the current sna } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); - var attributes = snapshot.attributes(); + let attributes = snapshot.attributes(); assert.deepEqual(attributes, { author: undefined, title: 'Hello World' }, 'attributes are returned correctly'); }); @@ -175,7 +175,7 @@ test("snapshot.attributes() returns a copy of all attributes for the current sna test("snapshot.changedAttributes() returns a copy of all changed attributes for the current snapshot", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -185,11 +185,11 @@ test("snapshot.changedAttributes() returns a copy of all changed attributes for } } }); - var post = env.store.peekRecord('post', 1); + let post = env.store.peekRecord('post', 1); post.set('title', 'Hello World!'); - var snapshot = post._createSnapshot(); + let snapshot = post._createSnapshot(); - var changes = snapshot.changedAttributes(); + let changes = snapshot.changedAttributes(); assert.deepEqual(changes.title, ['Hello World', 'Hello World!'], 'changed attributes are returned correctly'); }); @@ -198,7 +198,7 @@ test("snapshot.changedAttributes() returns a copy of all changed attributes for test("snapshot.belongsTo() returns undefined if relationship is undefined", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'comment', @@ -208,9 +208,9 @@ test("snapshot.belongsTo() returns undefined if relationship is undefined", func } } }); - var comment = env.store.peekRecord('comment', 1); - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post'); + let comment = env.store.peekRecord('comment', 1); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); assert.equal(relationship, undefined, 'relationship is undefined'); }); @@ -219,7 +219,7 @@ test("snapshot.belongsTo() returns undefined if relationship is undefined", func test("snapshot.belongsTo() returns null if relationship is unset", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: [{ type: 'post', @@ -240,9 +240,9 @@ test("snapshot.belongsTo() returns null if relationship is unset", function(asse } }] }); - var comment = env.store.peekRecord('comment', 2); - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post'); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); assert.equal(relationship, null, 'relationship is unset'); }); @@ -251,7 +251,7 @@ test("snapshot.belongsTo() returns null if relationship is unset", function(asse test("snapshot.belongsTo() returns a snapshot if relationship is set", function(assert) { assert.expect(3); - run(function() { + run(() => { env.store.push({ data: [{ type: 'post', @@ -272,9 +272,9 @@ test("snapshot.belongsTo() returns a snapshot if relationship is set", function( } }] }); - var comment = env.store.peekRecord('comment', 2); - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post'); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); assert.ok(relationship instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); assert.equal(relationship.id, '1', 'post id is correct'); @@ -285,7 +285,7 @@ test("snapshot.belongsTo() returns a snapshot if relationship is set", function( test("snapshot.belongsTo() returns null if relationship is deleted", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: [{ type: 'post', @@ -306,13 +306,13 @@ test("snapshot.belongsTo() returns null if relationship is deleted", function(as } }] }); - var post = env.store.peekRecord('post', 1); - var comment = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); post.deleteRecord(); - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post'); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); assert.equal(relationship, null, 'relationship unset after deleted'); }); @@ -321,7 +321,7 @@ test("snapshot.belongsTo() returns null if relationship is deleted", function(as test("snapshot.belongsTo() returns undefined if relationship is a link", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'comment', @@ -338,9 +338,9 @@ test("snapshot.belongsTo() returns undefined if relationship is a link", functio } } }); - var comment = env.store.peekRecord('comment', 2); - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post'); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); assert.equal(relationship, undefined, 'relationship is undefined'); }); @@ -349,7 +349,7 @@ test("snapshot.belongsTo() returns undefined if relationship is a link", functio test("snapshot.belongsTo() throws error if relation doesn't exist", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -359,10 +359,10 @@ test("snapshot.belongsTo() throws error if relation doesn't exist", function(ass } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); - assert.throws(function() { + assert.throws(() => { snapshot.belongsTo('unknown'); }, /has no belongsTo relationship named 'unknown'/, 'throws error'); }); @@ -375,7 +375,7 @@ test("snapshot.belongsTo() returns a snapshot if relationship link has been fetc return Ember.RSVP.resolve({ data: { id: 1, type: 'post', attributes: { title: 'Hello World' } } }); }; - run(function() { + return run(() => { env.store.push({ data: { type: 'comment', @@ -392,11 +392,11 @@ test("snapshot.belongsTo() returns a snapshot if relationship link has been fetc } } }); - var comment = env.store.peekRecord('comment', 2); + let comment = env.store.peekRecord('comment', 2); - comment.get('post').then(function(post) { - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post'); + return comment.get('post').then(post => { + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post'); assert.ok(relationship instanceof DS.Snapshot, 'snapshot is an instance of DS.Snapshot'); assert.equal(relationship.id, '1', 'post id is correct'); @@ -407,7 +407,7 @@ test("snapshot.belongsTo() returns a snapshot if relationship link has been fetc test("snapshot.belongsTo() and snapshot.hasMany() returns correctly when adding an object to a hasMany relationship", function(assert) { assert.expect(4); - run(function() { + return run(() => { env.store.push({ data: [{ type: 'post', @@ -423,17 +423,17 @@ test("snapshot.belongsTo() and snapshot.hasMany() returns correctly when adding } }] }); - var post = env.store.peekRecord('post', 1); - var comment = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); - post.get('comments').then(function(comments) { + return post.get('comments').then(comments => { comments.addObject(comment); - var postSnapshot = post._createSnapshot(); - var commentSnapshot = comment._createSnapshot(); + let postSnapshot = post._createSnapshot(); + let commentSnapshot = comment._createSnapshot(); - var hasManyRelationship = postSnapshot.hasMany('comments'); - var belongsToRelationship = commentSnapshot.belongsTo('post'); + let hasManyRelationship = postSnapshot.hasMany('comments'); + let belongsToRelationship = commentSnapshot.belongsTo('post'); assert.ok(hasManyRelationship instanceof Array, 'hasMany relationship is an instance of Array'); assert.equal(hasManyRelationship.length, 1, 'hasMany relationship contains related object'); @@ -447,7 +447,7 @@ test("snapshot.belongsTo() and snapshot.hasMany() returns correctly when adding test("snapshot.belongsTo() and snapshot.hasMany() returns correctly when setting an object to a belongsTo relationship", function(assert) { assert.expect(4); - run(function() { + run(() => { env.store.push({ data: [{ type: 'post', @@ -463,16 +463,16 @@ test("snapshot.belongsTo() and snapshot.hasMany() returns correctly when setting } }] }); - var post = env.store.peekRecord('post', 1); - var comment = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); comment.set('post', post); - var postSnapshot = post._createSnapshot(); - var commentSnapshot = comment._createSnapshot(); + let postSnapshot = post._createSnapshot(); + let commentSnapshot = comment._createSnapshot(); - var hasManyRelationship = postSnapshot.hasMany('comments'); - var belongsToRelationship = commentSnapshot.belongsTo('post'); + let hasManyRelationship = postSnapshot.hasMany('comments'); + let belongsToRelationship = commentSnapshot.belongsTo('post'); assert.ok(hasManyRelationship instanceof Array, 'hasMany relationship is an instance of Array'); assert.equal(hasManyRelationship.length, 1, 'hasMany relationship contains related object'); @@ -485,7 +485,7 @@ test("snapshot.belongsTo() and snapshot.hasMany() returns correctly when setting test("snapshot.belongsTo() returns ID if option.id is set", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: [{ type: 'post', @@ -506,9 +506,9 @@ test("snapshot.belongsTo() returns ID if option.id is set", function(assert) { } }] }); - var comment = env.store.peekRecord('comment', 2); - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post', { id: true }); + let comment = env.store.peekRecord('comment', 2); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post', { id: true }); assert.equal(relationship, '1', 'relationship ID correctly returned'); }); @@ -517,7 +517,7 @@ test("snapshot.belongsTo() returns ID if option.id is set", function(assert) { test("snapshot.belongsTo() returns null if option.id is set but relationship was deleted", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: [{ type: 'post', @@ -538,13 +538,13 @@ test("snapshot.belongsTo() returns null if option.id is set but relationship was } }] }); - var post = env.store.peekRecord('post', 1); - var comment = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 1); + let comment = env.store.peekRecord('comment', 2); post.deleteRecord(); - var snapshot = comment._createSnapshot(); - var relationship = snapshot.belongsTo('post', { id: true }); + let snapshot = comment._createSnapshot(); + let relationship = snapshot.belongsTo('post', { id: true }); assert.equal(relationship, null, 'relationship unset after deleted'); }); @@ -553,7 +553,7 @@ test("snapshot.belongsTo() returns null if option.id is set but relationship was test("snapshot.hasMany() returns undefined if relationship is undefined", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -563,9 +563,9 @@ test("snapshot.hasMany() returns undefined if relationship is undefined", functi } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments'); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); assert.equal(relationship, undefined, 'relationship is undefined'); }); @@ -574,7 +574,7 @@ test("snapshot.hasMany() returns undefined if relationship is undefined", functi test("snapshot.hasMany() returns empty array if relationship is empty", function(assert) { assert.expect(2); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -589,9 +589,9 @@ test("snapshot.hasMany() returns empty array if relationship is empty", function } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments'); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.equal(relationship.length, 0, 'relationship is empty'); @@ -601,7 +601,7 @@ test("snapshot.hasMany() returns empty array if relationship is empty", function test("snapshot.hasMany() returns array of snapshots if relationship is set", function(assert) { assert.expect(5); - run(function() { + run(() => { env.store.push({ data: [{ type: 'comment', @@ -631,14 +631,14 @@ test("snapshot.hasMany() returns array of snapshots if relationship is set", fun } }] }); - var post = env.store.peekRecord('post', 3); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments'); + let post = env.store.peekRecord('post', 3); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.equal(relationship.length, 2, 'relationship has two items'); - var relationship1 = relationship[0]; + let relationship1 = relationship[0]; assert.ok(relationship1 instanceof DS.Snapshot, 'relationship item is an instance of DS.Snapshot'); @@ -650,7 +650,7 @@ test("snapshot.hasMany() returns array of snapshots if relationship is set", fun test("snapshot.hasMany() returns empty array if relationship records are deleted", function(assert) { assert.expect(2); - run(function() { + run(() => { env.store.push({ data: [{ type: 'comment', @@ -680,15 +680,15 @@ test("snapshot.hasMany() returns empty array if relationship records are deleted } }] }); - var comment1 = env.store.peekRecord('comment', 1); - var comment2 = env.store.peekRecord('comment', 2); - var post = env.store.peekRecord('post', 3); + let comment1 = env.store.peekRecord('comment', 1); + let comment2 = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 3); comment1.deleteRecord(); comment2.deleteRecord(); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments'); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.equal(relationship.length, 0, 'relationship is empty'); @@ -698,7 +698,7 @@ test("snapshot.hasMany() returns empty array if relationship records are deleted test("snapshot.hasMany() returns array of IDs if option.ids is set", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -716,9 +716,9 @@ test("snapshot.hasMany() returns array of IDs if option.ids is set", function(as } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments', { ids: true }); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments', { ids: true }); assert.deepEqual(relationship, ['2', '3'], 'relationship IDs correctly returned'); }); @@ -727,7 +727,7 @@ test("snapshot.hasMany() returns array of IDs if option.ids is set", function(as test("snapshot.hasMany() returns empty array of IDs if option.ids is set but relationship records were deleted", function(assert) { assert.expect(2); - run(function() { + run(() => { env.store.push({ data: [{ type: 'comment', @@ -757,15 +757,15 @@ test("snapshot.hasMany() returns empty array of IDs if option.ids is set but rel } }] }); - var comment1 = env.store.peekRecord('comment', 1); - var comment2 = env.store.peekRecord('comment', 2); - var post = env.store.peekRecord('post', 3); + let comment1 = env.store.peekRecord('comment', 1); + let comment2 = env.store.peekRecord('comment', 2); + let post = env.store.peekRecord('post', 3); comment1.deleteRecord(); comment2.deleteRecord(); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments', { ids: true }); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments', { ids: true }); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.equal(relationship.length, 0, 'relationship is empty'); @@ -775,7 +775,7 @@ test("snapshot.hasMany() returns empty array of IDs if option.ids is set but rel test("snapshot.hasMany() returns undefined if relationship is a link", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -792,9 +792,9 @@ test("snapshot.hasMany() returns undefined if relationship is a link", function( } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments'); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); assert.equal(relationship, undefined, 'relationship is undefined'); }); @@ -807,7 +807,7 @@ test("snapshot.hasMany() returns array of snapshots if relationship link has bee return Ember.RSVP.resolve({ data: [{ id: 2, type: 'comment', attributes: { body: 'This is comment' } }]}); }; - run(function() { + return run(() => { env.store.push({ data: { type: 'post', @@ -824,11 +824,12 @@ test("snapshot.hasMany() returns array of snapshots if relationship link has bee } } }); - var post = env.store.peekRecord('post', 1); - post.get('comments').then(function(comments) { - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments'); + let post = env.store.peekRecord('post', 1); + + return post.get('comments').then(comments => { + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.equal(relationship.length, 1, 'relationship has one item'); @@ -839,7 +840,7 @@ test("snapshot.hasMany() returns array of snapshots if relationship link has bee test("snapshot.hasMany() throws error if relation doesn't exist", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -849,10 +850,10 @@ test("snapshot.hasMany() throws error if relation doesn't exist", function(asser } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); - assert.throws(function() { + assert.throws(() => { snapshot.hasMany('unknown'); }, /has no hasMany relationship named 'unknown'/, 'throws error'); }); @@ -861,7 +862,7 @@ test("snapshot.hasMany() throws error if relation doesn't exist", function(asser test("snapshot.hasMany() respects the order of items in the relationship", function(assert) { assert.expect(3); - run(function() { + run(() => { env.store.push({ data: [{ type: 'comment', @@ -898,14 +899,14 @@ test("snapshot.hasMany() respects the order of items in the relationship", funct } }] }); - var comment3 = env.store.peekRecord('comment', 3); - var post = env.store.peekRecord('post', 4); + let comment3 = env.store.peekRecord('comment', 3); + let post = env.store.peekRecord('post', 4); post.get('comments').removeObject(comment3); post.get('comments').insertAt(0, comment3); - var snapshot = post._createSnapshot(); - var relationship = snapshot.hasMany('comments'); + let snapshot = post._createSnapshot(); + let relationship = snapshot.hasMany('comments'); assert.equal(relationship[0].id, '3', 'order of comment 3 is correct'); assert.equal(relationship[1].id, '1', 'order of comment 1 is correct'); @@ -916,7 +917,7 @@ test("snapshot.hasMany() respects the order of items in the relationship", funct test("snapshot.eachAttribute() proxies to record", function(assert) { assert.expect(1); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -926,13 +927,11 @@ test("snapshot.eachAttribute() proxies to record", function(assert) { } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); - var attributes = []; - snapshot.eachAttribute(function(name) { - attributes.push(name); - }); + let attributes = []; + snapshot.eachAttribute(name => attributes.push(name)); assert.deepEqual(attributes, ['author', 'title'], 'attributes are iterated correctly'); }); }); @@ -940,15 +939,13 @@ test("snapshot.eachAttribute() proxies to record", function(assert) { test("snapshot.eachRelationship() proxies to record", function(assert) { assert.expect(2); - var getRelationships = function(snapshot) { - var relationships = []; - snapshot.eachRelationship(function(name) { - relationships.push(name); - }); + let getRelationships = function(snapshot) { + let relationships = []; + snapshot.eachRelationship(name => relationships.push(name)); return relationships; }; - run(function() { + run(() => { env.store.push({ data: [{ type: 'comment', @@ -964,9 +961,9 @@ test("snapshot.eachRelationship() proxies to record", function(assert) { } }] }); - var comment = env.store.peekRecord('comment', 1); - var post = env.store.peekRecord('post', 2); - var snapshot; + let comment = env.store.peekRecord('comment', 1); + let post = env.store.peekRecord('post', 2); + let snapshot; snapshot = comment._createSnapshot(); assert.deepEqual(getRelationships(snapshot), ['post'], 'relationships are iterated correctly'); @@ -983,7 +980,7 @@ test("snapshot.belongsTo() does not trigger a call to store._scheduleFetch", fun assert.ok(false, 'store._scheduleFetch should not be called'); }; - run(function() { + run(() => { env.store.push({ data: { type: 'comment', @@ -998,8 +995,8 @@ test("snapshot.belongsTo() does not trigger a call to store._scheduleFetch", fun } } }); - var comment = env.store.peekRecord('comment', 1); - var snapshot = comment._createSnapshot(); + let comment = env.store.peekRecord('comment', 1); + let snapshot = comment._createSnapshot(); snapshot.belongsTo('post'); }); @@ -1012,7 +1009,7 @@ test("snapshot.hasMany() does not trigger a call to store._scheduleFetch", funct assert.ok(false, 'store._scheduleFetch should not be called'); }; - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -1030,8 +1027,8 @@ test("snapshot.hasMany() does not trigger a call to store._scheduleFetch", funct } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); snapshot.hasMany('comments'); }); @@ -1040,7 +1037,7 @@ test("snapshot.hasMany() does not trigger a call to store._scheduleFetch", funct test("snapshot.serialize() serializes itself", function(assert) { assert.expect(2); - run(function() { + run(() => { env.store.push({ data: { type: 'post', @@ -1050,12 +1047,12 @@ test("snapshot.serialize() serializes itself", function(assert) { } } }); - var post = env.store.peekRecord('post', 1); - var snapshot = post._createSnapshot(); + let post = env.store.peekRecord('post', 1); + let snapshot = post._createSnapshot(); post.set('title', 'New Title'); - var expected = { + let expected = { data: { attributes: { author: undefined, diff --git a/tests/integration/store-test.js b/tests/integration/store-test.js index 4af6741d664..f3db892465d 100644 --- a/tests/integration/store-test.js +++ b/tests/integration/store-test.js @@ -7,22 +7,31 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; import { isEnabled } from 'ember-data/-private'; -var store, env; +let store, env; -var Person = DS.Model.extend({ +const Person = DS.Model.extend({ name: DS.attr('string'), cars: DS.hasMany('car', { async: false }) }); -Person.reopenClass({ toString: () => 'Person' }); -var run = Ember.run; +Person.reopenClass({ + toString() { + return 'Person' + } +}); -var Car = DS.Model.extend({ +const { run } = Ember; +const Car = DS.Model.extend({ make: DS.attr('string'), model: DS.attr('string'), person: DS.belongsTo('person', { async: false }) }); -Car.reopenClass({ toString: () => 'Car' }); + +Car.reopenClass({ + toString() { + return 'Car'; + } +}); function initializeStore(adapter) { env = setupStore({ @@ -45,12 +54,12 @@ module("integration/store - destroy", { }); function tap(obj, methodName, callback) { - var old = obj[methodName]; + let old = obj[methodName]; - var summary = { called: [] }; + let summary = { called: [] }; obj[methodName] = function() { - var result = old.apply(obj, arguments); + let result = old.apply(obj, arguments); if (callback) { callback.apply(obj, arguments); } @@ -65,10 +74,10 @@ test("destroying record during find doesn't cause error", function(assert) { assert.expect(0); let done = assert.async(); - var TestAdapter = DS.Adapter.extend({ + let TestAdapter = DS.Adapter.extend({ findRecord(store, type, id, snapshot) { - return new Ember.RSVP.Promise(function(resolve, reject) { - Ember.run.next(function() { + return new Ember.RSVP.Promise((resolve, reject) => { + Ember.run.next(() => { store.unloadAll(type.modelName); reject(); }); @@ -78,19 +87,17 @@ test("destroying record during find doesn't cause error", function(assert) { initializeStore(TestAdapter); - var type = "car"; - var id = 1; + let type = "car"; + let id = 1; - run(function() { - store.findRecord(type, id).then(done, done); - }); + return run(() => store.findRecord(type, id).then(done, done)); }); test("find calls do not resolve when the store is destroyed", function(assert) { assert.expect(0); let done = assert.async(); - var TestAdapter = DS.Adapter.extend({ + let TestAdapter = DS.Adapter.extend({ findRecord(store, type, id, snapshot) { store.destroy(); Ember.RSVP.resolve(null); @@ -100,8 +107,8 @@ test("find calls do not resolve when the store is destroyed", function(assert) { initializeStore(TestAdapter); - var type = "car"; - var id = 1; + let type = "car"; + let id = 1; store.push = function() { Ember.assert("The test should have destroyed the store by now", store.get("isDestroyed")); @@ -109,20 +116,15 @@ test("find calls do not resolve when the store is destroyed", function(assert) { throw new Error("We shouldn't be pushing data into the store when it is destroyed"); }; - run(function() { - store.findRecord(type, id); - }); + run(() => store.findRecord(type, id)); - setTimeout(function() { - done(); - }, 500); + setTimeout(() => done(), 500); }); - test("destroying the store correctly cleans everything up", function(assert) { - var car, person; + let car, person; env.adapter.shouldBackgroundReloadRecord = () => false; - run(function() { + run(() => { store.push({ data: [{ type: 'car', @@ -155,37 +157,34 @@ test("destroying the store correctly cleans everything up", function(assert) { person = store.peekRecord('person', 1); }); - var personWillDestroy = tap(person, 'willDestroy'); - var carWillDestroy = tap(car, 'willDestroy'); - var carsWillDestroy = run(function() { - return tap(car.get('person.cars'), 'willDestroy'); - }); + let personWillDestroy = tap(person, 'willDestroy'); + let carWillDestroy = tap(car, 'willDestroy'); + let carsWillDestroy = run(() => tap(car.get('person.cars'), 'willDestroy')); env.adapter.query = function() { - return { data: [{ - id: 2, - type: 'person', - attributes: { name: 'Yehuda' } - }]}; + return { + data: [ + { + id: 2, + type: 'person', + attributes: { name: 'Yehuda' } + } + ] + }; }; - var adapterPopulatedPeople, filterdPeople; - run(function() { - adapterPopulatedPeople = store.query('person', { + let adapterPopulatedPeople =run(() => { + return adapterPopulatedPeople = store.query('person', { someCrazy: 'query' }); }); - run(function() { - filterdPeople = store.filter('person', function() { return true; }); - }); + let filterdPeople = run(() => store.filter('person', () => true)); - var filterdPeopleWillDestroy = tap(filterdPeople.get('content'), 'willDestroy'); - var adapterPopulatedPeopleWillDestroy = tap(adapterPopulatedPeople.get('content'), 'willDestroy'); + let filterdPeopleWillDestroy = tap(filterdPeople.get('content'), 'willDestroy'); + let adapterPopulatedPeopleWillDestroy = tap(adapterPopulatedPeople.get('content'), 'willDestroy'); - run(function() { - store.findRecord('person', 2); - }); + run(() => store.findRecord('person', 2)); assert.equal(personWillDestroy.called.length, 0, 'expected person.willDestroy to not have been called'); assert.equal(carWillDestroy.called.length, 0, 'expected car.willDestroy to not have been called'); @@ -219,8 +218,6 @@ function ajaxResponse(value) { } } - - module("integration/store - findRecord"); test("store#findRecord fetches record from server when cached record is not present", function(assert) { @@ -240,8 +237,8 @@ test("store#findRecord fetches record from server when cached record is not pres let cachedRecordIsPresent = store.hasRecordForId('car', 20); assert.ok(!cachedRecordIsPresent, 'Car with id=20 should not exist'); - run(function() { - store.findRecord('car', 20).then(function(car) { + return run(() => { + return store.findRecord('car', 20).then(car => { assert.equal(car.get('make'), 'BMC', 'Car with id=20 is now loaded'); }); }); @@ -252,7 +249,7 @@ test("store#findRecord returns cached record immediately and reloads record in t initializeStore(DS.RESTAdapter.extend()); - run(function() { + run(() => { store.push({ data: { type: 'car', @@ -273,13 +270,13 @@ test("store#findRecord returns cached record immediately and reloads record in t }] }); - run(function() { - store.findRecord('car', 1).then(function(car) { + run(() => { + return store.findRecord('car', 1).then(car => { assert.equal(car.get('model'), 'Mini', 'cached car record is returned'); }); }); - run(function() { + run(() => { let car = store.peekRecord('car', 1); assert.equal(car.get('model'), 'Princess', 'car record was reloaded'); }); @@ -296,7 +293,7 @@ test("store#findRecord { reload: true } ignores cached record and reloads record initializeStore(testAdapter); - run(function() { + run(() => { store.push({ data: { type: 'car', @@ -320,8 +317,8 @@ test("store#findRecord { reload: true } ignores cached record and reloads record let cachedCar = store.peekRecord('car', 1); assert.equal(cachedCar.get('model'), 'Mini', 'cached car has expected model'); - run(function() { - store.findRecord('car', 1, { reload: true }).then(function(car) { + return run(() => { + return store.findRecord('car', 1, { reload: true }).then(car => { assert.equal(car.get('model'), 'Princess', 'cached record ignored, record reloaded via server'); }); }); @@ -465,9 +462,9 @@ testInDebug('store#findRecord call with `id` of type different than non-empty st initializeStore(DS.RESTAdapter.extend()); - run(function() { + run(() => { badValues.map(item => { - assert.expectAssertion(function() { + assert.expectAssertion(() => { store.findRecord('car', item); }, '`id` passed to `findRecord()` has to be non-empty string or number'); }); @@ -496,11 +493,11 @@ test("Using store#findAll with no records triggers a query", function(assert) { }] }); - var cars = store.peekAll('car'); + let cars = store.peekAll('car'); assert.ok(!cars.get('length'), 'There is no cars in the store'); - run(function() { - store.findAll('car').then(function(cars) { + return run(() => { + return store.findAll('car').then(cars => { assert.equal(cars.get('length'), 2, 'Two car were fetched'); }); }); @@ -509,7 +506,7 @@ test("Using store#findAll with no records triggers a query", function(assert) { test("Using store#findAll with existing records performs a query in the background, updating existing records and returning new ones", function(assert) { assert.expect(4); - run(function() { + run(() => { store.push({ data: { type: 'car', @@ -535,21 +532,23 @@ test("Using store#findAll with existing records performs a query in the backgrou }] }); - var cars = store.peekAll('car'); + let cars = store.peekAll('car'); assert.equal(cars.get('length'), 1, 'There is one car in the store'); - run(function() { - store.findAll('car').then(function(cars) { + let waiter = run(() => { + return store.findAll('car').then(cars => { assert.equal(cars.get('length'), 1, 'Store resolves with the existing records'); }); }); - run(function() { - var cars = store.peekAll('car'); + run(() => { + let cars = store.peekAll('car'); assert.equal(cars.get('length'), 2, 'There is 2 cars in the store now'); - var mini = cars.findBy('id', '1'); + let mini = cars.findBy('id', '1'); assert.equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); }); + + return waiter; }); test("store#findAll { backgroundReload: false } skips shouldBackgroundReloadAll, returns cached records & does not reload in the background", function(assert) { @@ -693,8 +692,8 @@ test("store#findAll { backgroundReload: false } is ignored if adapter.shouldRelo assert.equal(cars.get('firstObject.model'), 'Mini', 'correct car is in the store'); }); - run(() => { - store.findAll('car', { backgroundReload: false }).then((cars) => { + return run(() => { + return store.findAll('car', { backgroundReload: false }).then((cars) => { assert.equal(cars.get('length'), 2, 'multiple car records are returned'); assert.equal(cars.get('firstObject.model'), 'New Mini', 'initial car record was updated'); assert.equal(cars.get('lastObject.model'), 'Isetta', 'second car record was loaded'); @@ -705,7 +704,7 @@ test("store#findAll { backgroundReload: false } is ignored if adapter.shouldRelo test("store#findAll should eventually return all known records even if they are not in the adapter response", function(assert) { assert.expect(5); - run(function() { + run(() => { store.push({ data: [{ type: 'car', @@ -733,26 +732,28 @@ test("store#findAll should eventually return all known records even if they are }] }); - var cars = store.peekAll('car'); + let cars = store.peekAll('car'); assert.equal(cars.get('length'), 2, 'There is two cars in the store'); - run(function() { - store.findAll('car').then(function(cars) { + let waiter = run(() => { + return store.findAll('car').then(cars => { assert.equal(cars.get('length'), 2, 'It returns all cars'); - var carsInStore = store.peekAll('car'); + let carsInStore = store.peekAll('car'); assert.equal(carsInStore.get('length'), 2, 'There is 2 cars in the store'); }); }); - run(function() { - var cars = store.peekAll('car'); - var mini = cars.findBy('id', '1'); + run(() => { + let cars = store.peekAll('car'); + let mini = cars.findBy('id', '1'); assert.equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); - var carsInStore = store.peekAll('car'); + let carsInStore = store.peekAll('car'); assert.equal(carsInStore.get('length'), 2, 'There is 2 cars in the store'); }); + + return waiter; }); @@ -767,7 +768,7 @@ test("Using store#fetch on an empty record calls find", function(assert) { }] }); - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -786,11 +787,11 @@ test("Using store#fetch on an empty record calls find", function(assert) { }); }); - var car = store.recordForId('car', 20); + let car = store.recordForId('car', 20); assert.ok(car.get('isEmpty'), 'Car with id=20 should be empty'); - run(function() { - store.findRecord('car', 20, { reload: true }).then(function (car) { + return run(() => { + return store.findRecord('car', 20, { reload: true }).then(car => { assert.equal(car.get('make'), 'BMCW', 'Car with id=20 is now loaded'); }); }); @@ -799,8 +800,8 @@ test("Using store#fetch on an empty record calls find", function(assert) { test("Using store#adapterFor should not throw an error when looking up the application adapter", function(assert) { assert.expect(1); - run(function() { - var applicationAdapter = store.adapterFor('application'); + run(() => { + let applicationAdapter = store.adapterFor('application'); assert.ok(applicationAdapter); }); }); @@ -809,8 +810,8 @@ test("Using store#adapterFor should not throw an error when looking up the appli test("Using store#serializerFor should not throw an error when looking up the application serializer", function(assert) { assert.expect(1); - run(function() { - var applicationSerializer = store.serializerFor('application'); + run(() => { + let applicationSerializer = store.serializerFor('application'); assert.ok(applicationSerializer); }); }); @@ -823,9 +824,9 @@ module("integration/store - deleteRecord", { test("Using store#deleteRecord should mark the model for removal", function(assert) { assert.expect(3); - var person; + let person; - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -840,21 +841,18 @@ test("Using store#deleteRecord should mark the model for removal", function(asse assert.ok(store.hasRecordForId('person', 1), 'expected the record to be in the store'); - var personDeleteRecord = tap(person, 'deleteRecord'); + let personDeleteRecord = tap(person, 'deleteRecord'); - run(function() { - store.deleteRecord(person); - }); + run(() => store.deleteRecord(person)); assert.equal(personDeleteRecord.called.length, 1, 'expected person.deleteRecord to have been called'); assert.ok(person.get('isDeleted'), 'expect person to be isDeleted'); }); - test("Store should accept a null value for `data`", function(assert) { assert.expect(0); - run(function() { + run(() => { store.push({ data: null }); @@ -863,13 +861,13 @@ test("Store should accept a null value for `data`", function(assert) { testInDebug('store#findRecord that returns an array should assert', assert => { initializeStore(DS.JSONAPIAdapter.extend({ - findRecord: function() { + findRecord() { return { data: [] }; } })); - assert.expectAssertion(function() { - run(function() { + assert.expectAssertion(() => { + run(() => { store.findRecord('car', 1); }); }, /expected the primary data returned from a 'findRecord' response to be an object but instead it found an array/); @@ -880,9 +878,9 @@ testInDebug('store#didSaveRecord should assert when the response to a save does return {}; }; - assert.expectAssertion(function() { - run(function() { - var car = store.createRecord('car'); + assert.expectAssertion(() => { + run(() => { + let car = store.createRecord('car'); car.save(); }); }, /Your car record was saved to the server, but the response does not have an id and no id has been set client side. Records must have ids. Please update the server response to provide an id in the response or generate the id on the client side either before saving the record or while normalizing the response./); @@ -907,10 +905,8 @@ testInDebug('store#queryRecord should assert when normalized payload of adapter }; }; - assert.expectAssertion(function() { - run(function() { - store.queryRecord('car', {}); - }); + assert.expectAssertion(() => { + run(() => store.queryRecord('car', {})); }, /Expected the primary data returned by the serializer for a 'queryRecord' response to be a single object or null but instead it was an array./); });