Skip to content

Commit

Permalink
strip deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Nov 28, 2019
1 parent bf69e88 commit 5adecfe
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 286 deletions.
71 changes: 52 additions & 19 deletions packages/-ember-data/tests/unit/model/rollback-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RESTAdapter from '@ember-data/adapter/rest';
import RESTSerializer from '@ember-data/serializer/rest';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import { InvalidError } from '@ember-data/adapter/error';
import { DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS } from '@ember-data/private-build-infra/deprecations';

import { module, test } from 'qunit';

Expand Down Expand Up @@ -65,13 +66,17 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
});

assert.equal(person.get('firstName'), 'Thomas');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(() => person.rollbackAttributes());

assert.equal(person.get('firstName'), 'Tom');
assert.equal(person.get('hasDirtyAttributes'), false);
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});

test('changes to unassigned attributes can be rolled back', function(assert) {
Expand All @@ -95,13 +100,18 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
});

assert.equal(person.get('firstName'), 'Thomas');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(() => person.rollbackAttributes());

assert.strictEqual(person.get('firstName'), undefined);
assert.equal(person.get('hasDirtyAttributes'), false);
assert.equal(person.get('rolledBackCount'), 1);

if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});

test('changes to attributes made after a record is in-flight only rolls back the local changes', function(assert) {
Expand Down Expand Up @@ -139,7 +149,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
person.set('lastName', 'Dolly');

assert.equal(person.get('lastName'), 'Dolly');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

person.rollbackAttributes();

Expand All @@ -148,7 +160,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
assert.equal(person.get('isSaving'), true);

return saving.then(() => {
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
assert.equal(person.get('hasDirtyAttributes'), false, 'The person is now clean');
});
});
Expand Down Expand Up @@ -186,16 +200,19 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
person.save().then(null, function() {
assert.equal(person.get('isError'), true);
assert.deepEqual(person.changedAttributes().firstName, ['Tom', 'Thomas']);
assert.equal(person.get('rolledBackCount'), 0);

if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}
run(function() {
person.rollbackAttributes();
});

assert.equal(person.get('firstName'), 'Tom');
assert.equal(person.get('isError'), false);
assert.equal(Object.keys(person.changedAttributes()).length, 0);
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});
});
});
Expand Down Expand Up @@ -236,14 +253,18 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
.catch(() => {
assert.equal(person.get('isError'), true);
assert.equal(person.get('isDeleted'), true);
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(() => person.rollbackAttributes());

assert.equal(person.get('isDeleted'), false);
assert.equal(person.get('isError'), false);
assert.equal(person.get('hasDirtyAttributes'), false, 'must be not dirty');
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
})
.then(() => {
assert.equal(
Expand All @@ -261,14 +282,18 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho

assert.equal(person.get('isNew'), true, 'must be new');
assert.equal(person.get('hasDirtyAttributes'), true, 'must be dirty');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(person, 'rollbackAttributes');

assert.equal(person.get('isNew'), false, 'must not be new');
assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty');
assert.equal(person.get('isDeleted'), true, 'must be deleted');
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});

test(`invalid new record's attributes can be rollbacked`, function(assert) {
Expand Down Expand Up @@ -304,7 +329,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
assert.equal(person.get('isNew'), false, 'must not be new');
assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty');
assert.equal(person.get('isDeleted'), true, 'must be deleted');
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});
});
});
Expand Down Expand Up @@ -357,7 +384,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
'original name',
'after rollbackAttributes() firstName has the original value'
);
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});
});
});
Expand Down Expand Up @@ -394,10 +423,12 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
test("invalid record's attributes can be rollbacked", async function(assert) {
class Dog extends Model {
@attr() name;
rolledBackCount = 0;
rolledBack() {
}
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
Dog.prototype.rolledBackCount = 0;
Dog.prototype.rolledBack = function() {
this.incrementProperty('rolledBackCount');
}
};
}
const thrownAdapterError = new InvalidError([
{
Expand Down Expand Up @@ -457,7 +488,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
assert.equal(dog.get('name'), 'Pluto', 'Name is rolled back');
assert.notOk(dog.get('errors.name'), 'We have no errors for name anymore');
assert.ok(dog.get('isValid'), 'We are now in a valid state');
assert.equal(dog.get('rolledBackCount'), 1, 'we only rolled back once');
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(dog.get('rolledBackCount'), 1, 'we only rolled back once');
}
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { run } from '@ember/runloop';
import DS from 'ember-data';
import { module, test } from 'qunit';
const { AdapterPopulatedRecordArray, RecordArrayManager } = DS;
import Evented from '@ember/object/evented';
import { DEPRECATE_EVENTED_API_USAGE } from '@ember-data/private-build-infra/deprecations';

module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedRecordArray', function() {
function internalModelFor(record) {
Expand Down Expand Up @@ -125,9 +127,11 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
assert.equal(didAddRecord, 0, 'no records should have been added yet');

let didLoad = 0;
recordArray.on('didLoad', function() {
didLoad++;
});
if (DEPRECATE_EVENTED_API_USAGE) {
recordArray.on('didLoad', function() {
didLoad++;
});
}

let links = { foo: 1 };
let meta = { bar: 2 };
Expand All @@ -150,11 +154,15 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
'should now contain the loaded records'
);

assert.equal(didLoad, 0, 'didLoad event should not have fired');
if (DEPRECATE_EVENTED_API_USAGE) {
assert.equal(didLoad, 0, 'didLoad event should not have fired');
}
assert.equal(recordArray.get('links').foo, 1);
assert.equal(recordArray.get('meta').bar, 2);
});
assert.equal(didLoad, 1, 'didLoad event should have fired once');
if (DEPRECATE_EVENTED_API_USAGE) {
assert.equal(didLoad, 1, 'didLoad event should have fired once');
}
assert.expectDeprecation({
id: 'ember-data:evented-api-usage',
});
Expand All @@ -176,7 +184,8 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
assert.equal(array, recordArray);
}

let recordArray = AdapterPopulatedRecordArray.create({
// we need Evented to gain access to the @array:change event
let recordArray = AdapterPopulatedRecordArray.extend(Evented).create({
query: 'some-query',
manager: new RecordArrayManager({}),
});
Expand Down
66 changes: 37 additions & 29 deletions packages/-ember-data/tests/unit/store/push-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in
import { module, test } from 'qunit';

import DS from 'ember-data';
import { deprecatedTest } from '@ember-data/unpublished-test-infra/test-support/deprecated-test';

let store, Person, PhoneNumber, Post;
const { attr, hasMany, belongsTo } = DS;
Expand Down Expand Up @@ -147,40 +148,47 @@ module('unit/store/push - DS.Store#push', function(hooks) {
});
});

test(`Calling push triggers 'didLoad' even if the record hasn't been requested from the adapter`, async function(assert) {
assert.expect(2);

let didLoad = new EmberPromise((resolve, reject) => {
Person.reopen({
didLoad() {
try {
assert.ok(true, 'The didLoad callback was called');
resolve();
} catch (e) {
reject(e);
}
},
deprecatedTest(
`Calling push triggers 'didLoad' even if the record hasn't been requested from the adapter`,
{
id: 'ember-data:evented-api-usage',
until: '4.0',
},
async function(assert) {
assert.expect(2);

let didLoad = new EmberPromise((resolve, reject) => {
Person.reopen({
didLoad() {
try {
assert.ok(true, 'The didLoad callback was called');
resolve();
} catch (e) {
reject(e);
}
},
});
});
});

run(() => {
store.push({
data: {
type: 'person',
id: 'wat',
attributes: {
firstName: 'Yehuda',
lastName: 'Katz',
run(() => {
store.push({
data: {
type: 'person',
id: 'wat',
attributes: {
firstName: 'Yehuda',
lastName: 'Katz',
},
},
},
});
});
});

await didLoad;
assert.expectDeprecation({
id: 'ember-data:record-lifecycle-event-methods',
});
});
await didLoad;
assert.expectDeprecation({
id: 'ember-data:record-lifecycle-event-methods',
});
}
);

test('Calling push with partial records updates just those attributes', function(assert) {
assert.expect(2);
Expand Down
Loading

0 comments on commit 5adecfe

Please sign in to comment.