Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove !CUSTOM_MODEL_CLASS branches #7816

Merged
merged 9 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { defer, resolve } from 'rsvp';
import { setupTest } from 'ember-qunit';

import Adapter from '@ember-data/adapter';
import { RECORD_DATA_STATE } from '@ember-data/canary-features';
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import Store, { recordIdentifierFor } from '@ember-data/store';

Expand Down Expand Up @@ -130,12 +129,8 @@ module('Integration | Identifiers - lid reflection', function (hooks) {
assert.ok(pushedRecord === record, 'We have the same record instance');
assert.strictEqual(record.name, 'Chris', 'We use the in-flight name');
assert.strictEqual(record.age, 31, 'We received the pushed data');
if (RECORD_DATA_STATE) {
// once the payload is received the derived state shifts to "no longer new" in the RECORD_DATA_STATE world
assert.false(record.isNew, 'We are no longer in the new state');
} else {
assert.true(record.isNew, 'We are still in the new state');
}
// once the payload is received the derived state shifts to "no longer new" in the RECORD_DATA_STATE world
assert.false(record.isNew, 'We are no longer in the new state');

record.rollbackAttributes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Promise } from 'rsvp';
import { setupTest } from 'ember-qunit';

import { InvalidError } from '@ember-data/adapter/error';
import { RECORD_DATA_ERRORS } from '@ember-data/canary-features';
import Model, { attr } from '@ember-data/model';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import Store from '@ember-data/store';
Expand Down Expand Up @@ -113,10 +112,6 @@ let CustomStore = Store.extend({
});

module('integration/record-data - Custom RecordData Errors', function (hooks) {
if (!RECORD_DATA_ERRORS) {
return;
}

setupTest(hooks);

let store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Promise } from 'rsvp';

import { setupTest } from 'ember-qunit';

import { RECORD_DATA_STATE } from '@ember-data/canary-features';
import Model, { attr } from '@ember-data/model';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import Store from '@ember-data/store';
Expand Down Expand Up @@ -111,9 +110,6 @@ let CustomStore = Store.extend({
});

module('integration/record-data - Record Data State', function (hooks) {
if (!RECORD_DATA_STATE) {
return;
}
setupTest(hooks);

let store;
Expand Down
239 changes: 118 additions & 121 deletions packages/-ember-data/tests/integration/references/autotracking-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,148 +7,145 @@ import { module, test } from 'qunit';

import { setupRenderingTest } from 'ember-qunit';

import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
import { recordIdentifierFor } from '@ember-data/store';

if (CUSTOM_MODEL_CLASS) {
module('integration/references/autotracking', function (hooks) {
setupRenderingTest(hooks);

class User extends Model {
@attr name;
@belongsTo('user', { inverse: null, async: false })
bestFriend;
@hasMany('user', { inverse: null, async: false })
friends;
}

let store, user;
hooks.beforeEach(function () {
const { owner } = this;
owner.register('model:user', User);
store = owner.lookup('service:store');

owner.register(
'adapter:user',
class extends EmberObject {
createRecord() {
return { data: { id: '6', type: 'user' } };
}
module('integration/references/autotracking', function (hooks) {
setupRenderingTest(hooks);

class User extends Model {
@attr name;
@belongsTo('user', { inverse: null, async: false })
bestFriend;
@hasMany('user', { inverse: null, async: false })
friends;
}

let store, user;
hooks.beforeEach(function () {
const { owner } = this;
owner.register('model:user', User);
store = owner.lookup('service:store');

owner.register(
'adapter:user',
class extends EmberObject {
createRecord() {
return { data: { id: '6', type: 'user' } };
}
);
owner.register(
'serializer:user',
class extends EmberObject {
normalizeResponse(_, __, data) {
return data;
}
}
);
owner.register(
'serializer:user',
class extends EmberObject {
normalizeResponse(_, __, data) {
return data;
}
);

user = store.push({
data: {
type: 'user',
id: '1',
attributes: {
name: 'Chris',
}
);

user = store.push({
data: {
type: 'user',
id: '1',
attributes: {
name: 'Chris',
},
relationships: {
bestFriend: {
data: { type: 'user', id: '2' },
},
relationships: {
bestFriend: {
data: { type: 'user', id: '2' },
},
friends: {
data: [{ type: 'user', id: '2' }],
},
friends: {
data: [{ type: 'user', id: '2' }],
},
},
included: [
{ type: 'user', id: '2', attributes: { name: 'Igor' } },
{ type: 'user', id: '3', attributes: { name: 'David' } },
{ type: 'user', id: '4', attributes: { name: 'Scott' } },
{ type: 'user', id: '5', attributes: { name: 'Rob' } },
],
});
},
included: [
{ type: 'user', id: '2', attributes: { name: 'Igor' } },
{ type: 'user', id: '3', attributes: { name: 'David' } },
{ type: 'user', id: '4', attributes: { name: 'Scott' } },
{ type: 'user', id: '5', attributes: { name: 'Rob' } },
],
});
});

test('BelongsToReference.id() is autotracked', async function (assert) {
class TestContext {
user = user;
test('BelongsToReference.id() is autotracked', async function (assert) {
class TestContext {
user = user;

get bestFriendId() {
return this.user.belongsTo('bestFriend').id();
}
get bestFriendId() {
return this.user.belongsTo('bestFriend').id();
}
}

const testContext = new TestContext();
this.set('context', testContext);
await render(hbs`id: {{if this.context.bestFriendId this.context.bestFriendId 'null'}}`);

assert.strictEqual(getRootElement().textContent, 'id: 2', 'the id is initially correct');
assert.strictEqual(testContext.bestFriendId, '2', 'the id is initially correct');
user.bestFriend = store.createRecord('user', { name: 'Bill' });
await settled();
assert.strictEqual(getRootElement().textContent, 'id: null', 'the id updates to null');
assert.strictEqual(testContext.bestFriendId, null, 'the id is correct when we swap records');
await user.bestFriend.save();
await settled();
assert.strictEqual(getRootElement().textContent, 'id: 6', 'the id updates when the related record id updates');
assert.strictEqual(testContext.bestFriendId, '6', 'the id is correct when the record is saved');
});
const testContext = new TestContext();
this.set('context', testContext);
await render(hbs`id: {{if this.context.bestFriendId this.context.bestFriendId 'null'}}`);

assert.strictEqual(getRootElement().textContent, 'id: 2', 'the id is initially correct');
assert.strictEqual(testContext.bestFriendId, '2', 'the id is initially correct');
user.bestFriend = store.createRecord('user', { name: 'Bill' });
await settled();
assert.strictEqual(getRootElement().textContent, 'id: null', 'the id updates to null');
assert.strictEqual(testContext.bestFriendId, null, 'the id is correct when we swap records');
await user.bestFriend.save();
await settled();
assert.strictEqual(getRootElement().textContent, 'id: 6', 'the id updates when the related record id updates');
assert.strictEqual(testContext.bestFriendId, '6', 'the id is correct when the record is saved');
});

test('HasManyReference.ids() is autotracked', async function (assert) {
class TestContext {
user = user;
test('HasManyReference.ids() is autotracked', async function (assert) {
class TestContext {
user = user;

get friendIds() {
return this.user.hasMany('friends').ids();
}
get friendIds() {
return this.user.hasMany('friends').ids();
}
const testContext = new TestContext();
this.set('context', testContext);
await render(hbs`{{#each this.context.friendIds as |id|}}id: {{if id id 'null'}}, {{/each}}`);

assert.strictEqual(getRootElement().textContent, 'id: 2, ', 'the ids are initially correct');
assert.deepEqual(testContext.friendIds, ['2'], 'the ids are initially correct');
const bill = store.createRecord('user', { name: 'Bill' });
user.friends.pushObject(bill);
await settled();
assert.strictEqual(getRootElement().textContent, 'id: 2, id: null, ', 'the id is added for the new record');
assert.deepEqual(testContext.friendIds, ['2', null], 'the ids are correct when we add a new record');
await bill.save();
await settled();
assert.strictEqual(
getRootElement().textContent,
'id: 2, id: 6, ',
'the id updates when the related record id updates'
);
assert.deepEqual(testContext.friendIds, ['2', '6'], 'the ids are correct when the new record is saved');
});
}
const testContext = new TestContext();
this.set('context', testContext);
await render(hbs`{{#each this.context.friendIds as |id|}}id: {{if id id 'null'}}, {{/each}}`);

assert.strictEqual(getRootElement().textContent, 'id: 2, ', 'the ids are initially correct');
assert.deepEqual(testContext.friendIds, ['2'], 'the ids are initially correct');
const bill = store.createRecord('user', { name: 'Bill' });
user.friends.pushObject(bill);
await settled();
assert.strictEqual(getRootElement().textContent, 'id: 2, id: null, ', 'the id is added for the new record');
assert.deepEqual(testContext.friendIds, ['2', null], 'the ids are correct when we add a new record');
await bill.save();
await settled();
assert.strictEqual(
getRootElement().textContent,
'id: 2, id: 6, ',
'the id updates when the related record id updates'
);
assert.deepEqual(testContext.friendIds, ['2', '6'], 'the ids are correct when the new record is saved');
});

test('RecordReference.id() is autotracked', async function (assert) {
const dan = store.createRecord('user', { name: 'Dan' });
const identifier = recordIdentifierFor(dan);
const reference = store.getReference(identifier);
test('RecordReference.id() is autotracked', async function (assert) {
const dan = store.createRecord('user', { name: 'Dan' });
const identifier = recordIdentifierFor(dan);
const reference = store.getReference(identifier);

class TestContext {
user = reference;
class TestContext {
user = reference;

get id() {
return this.user.id();
}
get id() {
return this.user.id();
}
}

const testContext = new TestContext();
this.set('context', testContext);
const testContext = new TestContext();
this.set('context', testContext);

await render(hbs`id: {{if this.context.id this.context.id 'null'}}`);
await render(hbs`id: {{if this.context.id this.context.id 'null'}}`);

assert.strictEqual(getRootElement().textContent, 'id: null', 'the id is null');
assert.strictEqual(testContext.id, null, 'the id is correct initially');
await dan.save();
await settled();
assert.strictEqual(getRootElement().textContent, 'id: 6', 'the id updates when the record id updates');
assert.strictEqual(testContext.id, '6', 'the id is correct when the record is saved');
});
assert.strictEqual(getRootElement().textContent, 'id: null', 'the id is null');
assert.strictEqual(testContext.id, null, 'the id is correct initially');
await dan.save();
await settled();
assert.strictEqual(getRootElement().textContent, 'id: 6', 'the id updates when the record id updates');
assert.strictEqual(testContext.id, '6', 'the id is correct when the record is saved');
});
}
});
Loading