From b9151abd7b98208f2c342e27d05c687612258de8 Mon Sep 17 00:00:00 2001 From: pete Date: Mon, 6 May 2019 21:31:02 -0700 Subject: [PATCH] Adding deprecatedTest --- .../tests/helpers/deprecated-test.js | 25 +++-- .../tests/integration/lifecycle-hooks-test.js | 77 +++++++------ .../relationships/has-many-test.js | 106 ++++++++++-------- packages/-ember-data/tests/unit/model-test.js | 98 +++++++++------- .../addon/-private/system/model/model.js | 1 - 5 files changed, 177 insertions(+), 130 deletions(-) diff --git a/packages/-ember-data/tests/helpers/deprecated-test.js b/packages/-ember-data/tests/helpers/deprecated-test.js index 8501b71adf7..f4ccb08b029 100644 --- a/packages/-ember-data/tests/helpers/deprecated-test.js +++ b/packages/-ember-data/tests/helpers/deprecated-test.js @@ -1,8 +1,18 @@ -// import { gte } from 'ember-compatibility-helpers'; import { test } from 'qunit'; import VERSION from 'ember-data/version'; -export function deprecatedTest(deprecation, testName, testCallback) { +// small comparison function for major and minor semver values +function gte(EDVersion, DeprecationVersion) { + let _edv = EDVersion.split('.'); + let _depv = DeprecationVersion.split('.'); + // compare major + let major = +_edv[0] >= +_depv[0]; + // compare minor + let minor = +_edv[1] >= +_depv[1]; + return major || minor; +} + +export function deprecatedTest(testName, deprecation, testCallback) { // '4.0' if (typeof deprecation.until !== 'string' || deprecation.until.length < 3) { throw new Error(`deprecatedTest expects { until } to be a version.`); @@ -11,14 +21,11 @@ export function deprecatedTest(deprecation, testName, testCallback) { if (typeof deprecation.id !== 'string' || deprecation.id.length < 8) { throw new Error(`deprecatedTest expects { id } to be a meaningful string`); } - // gte('ember-data', '3.12') - if (VERSION <= deprecation.until) { - return test( - `DEPRECATION ${deprecation.id} until ${deprecation.until} | ${testName}`, - testCallback - ); + + if (gte(VERSION, deprecation.until)) { + test(`DEPRECATION ${deprecation.id} until ${deprecation.until} | ${testName}`, testCallback); } else { - return test(`DEPRECATION ${deprecation.id} until ${ + test(`DEPRECATION ${deprecation.id} until ${ deprecation.until } | ${testName}`, function(assert) { if (deprecation.refactor === true) { diff --git a/packages/-ember-data/tests/integration/lifecycle-hooks-test.js b/packages/-ember-data/tests/integration/lifecycle-hooks-test.js index 12b389e48ba..f04d1e01907 100644 --- a/packages/-ember-data/tests/integration/lifecycle-hooks-test.js +++ b/packages/-ember-data/tests/integration/lifecycle-hooks-test.js @@ -1,8 +1,9 @@ import { resolve } from 'rsvp'; import { run } from '@ember/runloop'; +import { deprecatedTest } from 'dummy/tests/helpers/deprecated-test'; import setupStore from 'dummy/tests/helpers/store'; -import { module, skip as test, test as realTest } from 'qunit'; +import { module } from 'qunit'; import DS from 'ember-data'; @@ -25,44 +26,54 @@ module('integration/lifecycle_hooks - Lifecycle Hooks', { }, }); -realTest('ok', function(assert) { - assert.ok(true, 'i am skipped'); -}); - -test('When the adapter acknowledges that a record has been created, a `didCreate` event is triggered.', function(assert) { - let done = assert.async(); - assert.expect(3); +deprecatedTest( + 'When the adapter acknowledges that a record has been created, a `didCreate` event is triggered.', + { + id: 'ember-evented', + until: '3.12', + }, + function(assert) { + let done = assert.async(); + assert.expect(3); - env.adapter.createRecord = function(store, type, snapshot) { - return resolve({ data: { id: 99, type: 'person', attributes: { name: 'Yehuda Katz' } } }); - }; + env.adapter.createRecord = function(store, type, snapshot) { + return resolve({ data: { id: 99, type: 'person', attributes: { name: 'Yehuda Katz' } } }); + }; - let person = env.store.createRecord('person', { name: 'Yehuda Katz' }); + let person = env.store.createRecord('person', { name: 'Yehuda Katz' }); - person.on('didCreate', function() { - assert.equal(this, person, 'this is bound to the record'); - assert.equal(this.get('id'), '99', 'the ID has been assigned'); - assert.equal(this.get('name'), 'Yehuda Katz', 'the attribute has been assigned'); - done(); - }); + person.on('didCreate', function() { + assert.equal(this, person, 'this is bound to the record'); + assert.equal(this.get('id'), '99', 'the ID has been assigned'); + assert.equal(this.get('name'), 'Yehuda Katz', 'the attribute has been assigned'); + done(); + }); - run(person, 'save'); -}); + run(person, 'save'); + } +); -test('When the adapter acknowledges that a record has been created without a new data payload, a `didCreate` event is triggered.', function(assert) { - assert.expect(3); +deprecatedTest( + 'When the adapter acknowledges that a record has been created without a new data payload, a `didCreate` event is triggered.', + { + id: 'ember-evented', + until: '3.12', + }, + function(assert) { + assert.expect(3); - env.adapter.createRecord = function(store, type, snapshot) { - return resolve(); - }; + env.adapter.createRecord = function(store, type, snapshot) { + return resolve(); + }; - let person = env.store.createRecord('person', { id: 99, name: 'Yehuda Katz' }); + let person = env.store.createRecord('person', { id: 99, name: 'Yehuda Katz' }); - person.on('didCreate', function() { - assert.equal(this, person, 'this is bound to the record'); - assert.equal(this.get('id'), '99', 'the ID has been assigned'); - assert.equal(this.get('name'), 'Yehuda Katz', 'the attribute has been assigned'); - }); + person.on('didCreate', function() { + assert.equal(this, person, 'this is bound to the record'); + assert.equal(this.get('id'), '99', 'the ID has been assigned'); + assert.equal(this.get('name'), 'Yehuda Katz', 'the attribute has been assigned'); + }); - run(person, 'save'); -}); + run(person, 'save'); + } +); diff --git a/packages/-ember-data/tests/integration/relationships/has-many-test.js b/packages/-ember-data/tests/integration/relationships/has-many-test.js index c42b059cd98..160e0cdac81 100644 --- a/packages/-ember-data/tests/integration/relationships/has-many-test.js +++ b/packages/-ember-data/tests/integration/relationships/has-many-test.js @@ -6,6 +6,7 @@ import { get } from '@ember/object'; import { run } from '@ember/runloop'; import setupStore from 'dummy/tests/helpers/store'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; +import { deprecatedTest } from 'dummy/tests/helpers/deprecated-test'; import { module, test, skip } from 'qunit'; import { relationshipStateFor, relationshipsFor } from 'ember-data/-private'; import DS from 'ember-data'; @@ -1267,71 +1268,78 @@ test('PromiseArray proxies createRecord to its ManyArray once the hasMany is loa }); }); -test('PromiseArray proxies evented methods to its ManyArray', function(assert) { - assert.expect(6); - - Post.reopen({ - comments: DS.hasMany('comment', { async: true }), - }); +deprecatedTest( + 'PromiseArray proxies evented methods to its ManyArray', + { + id: 'ember-evented', + until: '3.12', + }, + function(assert) { + assert.expect(6); - env.adapter.findHasMany = function(store, snapshot, link, relationship) { - return resolve({ - data: [ - { id: 1, type: 'comment', attributes: { body: 'First' } }, - { id: 2, type: 'comment', attributes: { body: 'Second' } }, - ], + Post.reopen({ + comments: DS.hasMany('comment', { async: true }), }); - }; - let post, comments; - run(function() { - env.store.push({ - data: { - type: 'post', - id: '1', - relationships: { - comments: { - links: { - related: 'someLink', + env.adapter.findHasMany = function(store, snapshot, link, relationship) { + return resolve({ + data: [ + { id: 1, type: 'comment', attributes: { body: 'First' } }, + { id: 2, type: 'comment', attributes: { body: 'Second' } }, + ], + }); + }; + let post, comments; + + run(function() { + env.store.push({ + data: { + type: 'post', + id: '1', + relationships: { + comments: { + links: { + related: 'someLink', + }, }, }, }, - }, + }); + post = env.store.peekRecord('post', 1); + comments = post.get('comments'); }); - post = env.store.peekRecord('post', 1); - comments = post.get('comments'); - }); - comments.on('on-event', function() { - assert.ok(true); - }); + comments.on('on-event', function() { + assert.ok(true); + }); - run(function() { - comments.trigger('on-event'); - }); + run(function() { + comments.trigger('on-event'); + }); - assert.equal(comments.has('on-event'), true); - const cb = function() { - assert.ok(false, 'We should not trigger this event'); - }; + assert.equal(comments.has('on-event'), true); + const cb = function() { + assert.ok(false, 'We should not trigger this event'); + }; - comments.on('off-event', cb); - comments.off('off-event', cb); + comments.on('off-event', cb); + comments.off('off-event', cb); - assert.equal(comments.has('off-event'), false); + assert.equal(comments.has('off-event'), false); - comments.one('one-event', function() { - assert.ok(true); - }); + comments.one('one-event', function() { + assert.ok(true); + }); - assert.equal(comments.has('one-event'), true); + assert.equal(comments.has('one-event'), true); - run(function() { - comments.trigger('one-event'); - }); + run(function() { + comments.trigger('one-event'); + }); - assert.equal(comments.has('one-event'), false); -}); + assert.equal(comments.has('one-event'), false); + } +); test('An updated `links` value should invalidate a relationship cache', function(assert) { assert.expect(8); diff --git a/packages/-ember-data/tests/unit/model-test.js b/packages/-ember-data/tests/unit/model-test.js index 538e9e0b716..dd71c811dff 100644 --- a/packages/-ember-data/tests/unit/model-test.js +++ b/packages/-ember-data/tests/unit/model-test.js @@ -2,7 +2,8 @@ import { guidFor } from '@ember/object/internals'; import { resolve, reject } from 'rsvp'; import { set, get, observer, computed } from '@ember/object'; import testInDebug from 'dummy/tests/helpers/test-in-debug'; -import { module, test, skip } from 'qunit'; +import { module, test } from 'qunit'; +import { deprecatedTest } from 'dummy/tests/helpers/deprecated-test'; import { settled } from '@ember/test-helpers'; import { setupTest } from 'ember-qunit'; import Model from '@ember-data/model'; @@ -607,58 +608,79 @@ module('unit/model - Model', function(hooks) { }); module('Evented', function() { - skip('an event listener can be added to a record', async function(assert) { - let count = 0; - let F = function() { - count++; - }; + deprecatedTest( + 'an event listener can be added to a record', + { + id: 'ember-evented', + until: '3.12', + }, + async function(assert) { + let count = 0; + let F = function() { + count++; + }; - let record = store.createRecord('person'); + let record = store.createRecord('person'); - record.on('event!', F); - record.trigger('event!'); + record.on('event!', F); + record.trigger('event!'); - await settled(); + await settled(); - assert.equal(count, 1, 'the event was triggered'); - record.trigger('event!'); + assert.equal(count, 1, 'the event was triggered'); + record.trigger('event!'); - await settled(); + await settled(); - assert.equal(count, 2, 'the event was triggered'); - }); + assert.equal(count, 2, 'the event was triggered'); + } + ); - skip('when an event is triggered on a record the method with the same name is invoked with arguments', async function(assert) { - let count = 0; - let F = function() { - count++; - }; - let record = store.createRecord('person'); + deprecatedTest( + 'when an event is triggered on a record the method with the same name is invoked with arguments', + { + id: 'ember-evented', + until: '3.12', + }, + async function(assert) { + let count = 0; + let F = function() { + count++; + }; + let record = store.createRecord('person'); - record.eventNamedMethod = F; + record.eventNamedMethod = F; - record.trigger('eventNamedMethod'); + record.trigger('eventNamedMethod'); - await settled(); + await settled(); - assert.equal(count, 1, 'the corresponding method was called'); - }); + assert.equal(count, 1, 'the corresponding method was called'); + } + ); - skip('when a method is invoked from an event with the same name the arguments are passed through', async function(assert) { - let eventMethodArgs = null; - let F = function() { - eventMethodArgs = arguments; - }; - let record = store.createRecord('person'); + deprecatedTest( + 'when a method is invoked from an event with the same name the arguments are passed through', + { + id: 'ember-evented', + until: '3.12', + }, + async function(assert) { + let eventMethodArgs = null; + let F = function() { + eventMethodArgs = arguments; + }; + let record = store.createRecord('person'); - record.eventThatTriggersMethod = F; - record.trigger('eventThatTriggersMethod', 1, 2); + record.eventThatTriggersMethod = F; + record.trigger('eventThatTriggersMethod', 1, 2); - await settled(); + await settled(); - assert.equal(eventMethodArgs[0], 1); - assert.equal(eventMethodArgs[1], 2); - }); + assert.equal(eventMethodArgs[0], 1); + assert.equal(eventMethodArgs[1], 2); + } + ); }); module('Reserved Props', function() { diff --git a/packages/store/addon/-private/system/model/model.js b/packages/store/addon/-private/system/model/model.js index 9cf1cf53b0b..98384e2819f 100644 --- a/packages/store/addon/-private/system/model/model.js +++ b/packages/store/addon/-private/system/model/model.js @@ -1,6 +1,5 @@ import { isNone } from '@ember/utils'; import EmberError from '@ember/error'; -//import Evented from '@ember/object/evented'; import DeprecatedEvented from '../deprecated-evented'; import EmberObject, { computed, get } from '@ember/object'; import { DEBUG } from '@glimmer/env';