diff --git a/packages/-ember-data/package.json b/packages/-ember-data/package.json index ac0448f3c1f..3aecbdf2bda 100644 --- a/packages/-ember-data/package.json +++ b/packages/-ember-data/package.json @@ -73,13 +73,14 @@ "ember-qunit": "*", "ember-qunit-assert-helpers": "*", "ember-resolver": "*", - "ember-source": "*", + "ember-source": "~3.4.0", "ember-source-channel-url": "*", "ember-try": "*", "github": "*", "json-typescript": "*", "loader.js": "*", - "typescript": "*" + "typescript": "*", + "@ember/jquery": "^0.6.0" }, "engines": { "node": ">= 8.0.0" @@ -91,4 +92,4 @@ "ember-addon": { "configPath": "tests/dummy/config" } -} +} \ No newline at end of file diff --git a/packages/-ember-data/tests/integration/adapter/find-all-test.js b/packages/-ember-data/tests/integration/adapter/find-all-test.js index 2ca7067d3b7..8bb05732754 100644 --- a/packages/-ember-data/tests/integration/adapter/find-all-test.js +++ b/packages/-ember-data/tests/integration/adapter/find-all-test.js @@ -141,7 +141,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function( ); }); - test('When all records for a type are requested, records that are created on the client should be added to the record array.', assert => { + test('When all records for a type are requested, records that are created on the client should be added to the record array.', async assert => { assert.expect(3); let allRecords = store.peekAll('person'); @@ -153,6 +153,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function( ); store.createRecord('person', { name: 'Carsten Nielsen' }); + await settled(); assert.equal(get(allRecords, 'length'), 1, "the record array's length is 1"); assert.equal( diff --git a/packages/-ember-data/tests/integration/inverse-test.js b/packages/-ember-data/tests/integration/inverse-test.js index 36d29a0d6b2..881ae2d0572 100644 --- a/packages/-ember-data/tests/integration/inverse-test.js +++ b/packages/-ember-data/tests/integration/inverse-test.js @@ -15,11 +15,13 @@ function stringify(string) { module('integration/inverse_test - inverseFor', function(hooks) { setupTest(hooks); let store; - let user; - let job; hooks.beforeEach(function() { let { owner } = this; + store = owner.lookup('service:store'); + }); + + test('Finds the inverse when there is only one possible available', function(assert) { class User extends Model { @attr() name; @@ -47,25 +49,12 @@ module('integration/inverse_test - inverseFor', function(hooks) { } } - class ReflexiveModel extends Model { - @belongsTo('reflexive-model', { async: false }) - reflexiveProp; - - toString() { - return stringify('reflexiveModel'); - } - } + let { owner } = this; owner.register('model:user', User); owner.register('model:job', Job); - owner.register('model:reflexive-model', ReflexiveModel); - - store = owner.lookup('service:store'); - - job = store.modelFor('job'); - user = store.modelFor('user'); - }); - test('Finds the inverse when there is only one possible available', function(assert) { + let job = store.modelFor('job'); + let user = store.modelFor('user'); let inverseDefinition = job.inverseFor('user', store); assert.deepEqual( @@ -83,13 +72,45 @@ module('integration/inverse_test - inverseFor', function(hooks) { }); test('Finds the inverse when only one side has defined it manually', function(assert) { - job.reopen({ - owner: belongsTo('user', { inverse: 'previousJob', async: false }), - }); + class User extends Model { + @attr() + name; - user.reopen({ - previousJob: belongsTo('job', { async: false }), - }); + @belongsTo('user', { async: true, inverse: null }) + bestFriend; + + @belongsTo('job', { async: false }) + job; + + @belongsTo('job', { async: false }) + previousJob; + + toString() { + return stringify('user'); + } + } + + class Job extends Model { + @attr() + isGood; + + @belongsTo('user', { async: false }) + user; + + @belongsTo('user', { inverse: 'previousJob', async: false }) + owner; + + toString() { + return stringify('job'); + } + } + + let { owner } = this; + owner.register('model:user', User); + owner.register('model:job', Job); + + let job = store.modelFor('job'); + let user = store.modelFor('user'); assert.deepEqual( job.inverseFor('owner', store), @@ -120,10 +141,38 @@ module('integration/inverse_test - inverseFor', function(hooks) { }); test('Returns null if inverse relationship it is manually set with a different relationship key', function(assert) { - job.reopen({ - user: belongsTo('user', { inverse: 'previousJob', async: false }), - }); + class User extends Model { + @attr() + name; + + @belongsTo('user', { async: true, inverse: null }) + bestFriend; + + @belongsTo('job', { async: false }) + job; + + toString() { + return stringify('user'); + } + } + class Job extends Model { + @attr() + isGood; + + @belongsTo('user', { inverse: 'previousJob', async: false }) + user; + + toString() { + return stringify('job'); + } + } + + let { owner } = this; + owner.register('model:user', User); + owner.register('model:job', Job); + + let user = store.modelFor('user'); user.reopen({ job: belongsTo('job', { async: false }), }); @@ -132,15 +181,40 @@ module('integration/inverse_test - inverseFor', function(hooks) { }); testInDebug('Errors out if you define 2 inverses to the same model', function(assert) { - job.reopen({ - user: belongsTo('user', { inverse: 'job', async: false }), - owner: belongsTo('user', { inverse: 'job', async: false }), - }); + class User extends Model { + @attr() + name; - user.reopen({ - job: belongsTo('job', { async: false }), - }); + @belongsTo('user', { async: true, inverse: null }) + bestFriend; + + @belongsTo('job', { async: false }) + job; + + toString() { + return stringify('user'); + } + } + + class Job extends Model { + @attr() + isGood; + + @belongsTo('user', { inverse: 'job', async: false }) + user; + + @belongsTo('user', { inverse: 'job', async: false }) + owner; + + toString() { + return stringify('job'); + } + } + let { owner } = this; + owner.register('model:user', User); + owner.register('model:job', Job); + let user = store.modelFor('user'); assert.expectAssertion(() => { user.inverseFor('job', store); }, /Assertion Failed: You defined the 'job' relationship on model:user, but you defined the inverse relationships of type model:job multiple times/i); @@ -148,6 +222,37 @@ module('integration/inverse_test - inverseFor', function(hooks) { test('Caches findInverseFor return value', function(assert) { assert.expect(1); + class User extends Model { + @attr() + name; + + @belongsTo('user', { async: true, inverse: null }) + bestFriend; + + @belongsTo('job', { async: false }) + job; + + toString() { + return stringify('user'); + } + } + + class Job extends Model { + @attr() + isGood; + + @belongsTo('user', { async: false }) + user; + + toString() { + return stringify('job'); + } + } + let { owner } = this; + owner.register('model:user', User); + owner.register('model:job', Job); + + let job = store.modelFor('job'); let inverseForUser = job.inverseFor('user', store); job.findInverseFor = function() { @@ -158,6 +263,18 @@ module('integration/inverse_test - inverseFor', function(hooks) { }); testInDebug('Errors out if you do not define an inverse for a reflexive relationship', function(assert) { + class ReflexiveModel extends Model { + @belongsTo('reflexive-model', { async: false }) + reflexiveProp; + + toString() { + return stringify('reflexiveModel'); + } + } + + let { owner } = this; + owner.register('model:reflexive-model', ReflexiveModel); + //Maybe store is evaluated lazily, so we need this :( assert.expectWarning(() => { var reflexiveModel; diff --git a/packages/-ember-data/tests/integration/record-array-manager-test.js b/packages/-ember-data/tests/integration/record-array-manager-test.js index f5c9a1ad35c..e2cb2b3de1f 100644 --- a/packages/-ember-data/tests/integration/record-array-manager-test.js +++ b/packages/-ember-data/tests/integration/record-array-manager-test.js @@ -135,7 +135,7 @@ module('integration/record_array_manager', function(hooks) { assert.deepEqual(cars.toArray(), []); assert.equal(arrayContentWillChangeCount, 0, 'expected NO arrayChangeEvents yet'); - await store.push({ + store.push({ data: [ { type: 'car', @@ -155,6 +155,7 @@ module('integration/record_array_manager', function(hooks) { }, ], }); + await settled(); assert.equal(arrayContentWillChangeCount, 1, 'expected ONE array change event'); @@ -173,7 +174,7 @@ module('integration/record_array_manager', function(hooks) { arrayContentWillChangeCount = 0; - await store.push({ + store.push({ data: [ { type: 'car', @@ -185,10 +186,11 @@ module('integration/record_array_manager', function(hooks) { }, ], }); + await settled(); assert.equal(arrayContentWillChangeCount, 0, 'expected NO array change events'); - await store.push({ + store.push({ data: [ { type: 'car', @@ -200,6 +202,7 @@ module('integration/record_array_manager', function(hooks) { }, ], }); + await settled(); assert.equal(arrayContentWillChangeCount, 1, 'expected ONE array change event'); // reset function so it doesn't execute after test finishes and store is torn down @@ -222,7 +225,8 @@ module('integration/record_array_manager', function(hooks) { let adapterPopulated = manager.createAdapterPopulatedRecordArray('car', query); - await adapterPopulated.destroy(); + adapterPopulated.destroy(); + await settled(); assert.equal(manager._adapterPopulatedRecordArrays.length, 0); }); diff --git a/packages/-ember-data/tests/integration/record-arrays/adapter-populated-record-array-test.js b/packages/-ember-data/tests/integration/record-arrays/adapter-populated-record-array-test.js index e712215893b..d0f5ee1b394 100644 --- a/packages/-ember-data/tests/integration/record-arrays/adapter-populated-record-array-test.js +++ b/packages/-ember-data/tests/integration/record-arrays/adapter-populated-record-array-test.js @@ -1,6 +1,7 @@ import { run } from '@ember/runloop'; import { Promise } from 'rsvp'; import { setupStore, createStore } from 'dummy/tests/helpers/store'; +import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; @@ -151,8 +152,9 @@ module('integration/record-arrays/adapter_populated_record_array - DS.AdapterPop ); }); - test('recordArray.replace() throws error', function(assert) { + test('recordArray.replace() throws error', async function(assert) { let recordArray = store.recordArrayManager.createAdapterPopulatedRecordArray('person', null); + await settled(); assert.throws( () => { diff --git a/packages/-ember-data/tests/integration/snapshot-test.js b/packages/-ember-data/tests/integration/snapshot-test.js index d0a59e5b1b3..77c4f7d2b9a 100644 --- a/packages/-ember-data/tests/integration/snapshot-test.js +++ b/packages/-ember-data/tests/integration/snapshot-test.js @@ -458,7 +458,7 @@ module('integration/snapshot - Snapshot', function(hooks) { }); test('snapshot.belongsTo() returns a snapshot if relationship link has been fetched', async function(assert) { - assert.expect(2); + assert.expect(4); store.adapterFor('application').findBelongsTo = function(store, snapshot, link, relationship) { return resolve({ data: { id: 1, type: 'post', attributes: { title: 'Hello World' } } });