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

[CHORE]: Extract internalModel access to identifiers in RecordArray modules #6715

Merged
merged 1 commit into from
Jul 30, 2020
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
9 changes: 5 additions & 4 deletions packages/-ember-data/node-tests/fixtures/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ module.exports = {
'(private) @ember-data/serializer JSONSerializer#normalizeUsingDeclaredMapping',
'(private) @ember-data/serializer JSONSerializer#transformFor',
'(private) @ember-data/serializer RESTSerializer#_normalizeArray',
'(private) @ember-data/store AdapterPopulatedRecordArray#_setInternalModels',
'(private) @ember-data/store Errors#_add',
'(private) @ember-data/store Errors#_clear',
'(private) @ember-data/store Errors#_findOrCreateMessages',
Expand All @@ -69,12 +68,13 @@ module.exports = {
'(private) @ember-data/store ManyArray#isPolymorphic',
'(private) @ember-data/store ManyArray#promise',
'(private) @ember-data/store ManyArray#relationship',
'(private) @ember-data/store RecordArray#_pushInternalModels',
'(private) @ember-data/store RecordArray#_unregisterFromManager',
'(private) @ember-data/store RecordArray#content',
'(private) @ember-data/store RecordArray#objectAtContent',
'(private) @ember-data/store RecordArray#removeInternalModel',
'(private) @ember-data/store RecordArray#store',
'(private) @ember-data/store RecordArrayManager#_associateWithRecordArray',
'(private) @ember-data/store RecordArray#_pushInternalModels',
'(private) @ember-data/store RecordArray#_removeInternalModels',
'(private) @ember-data/store RecordArray#_unregisterFromManager',
'(private) @ember-data/store SnapshotRecordArray#_recordArray',
'(private) @ember-data/store SnapshotRecordArray#_snapshots',
'(private) @ember-data/store Store#_didUpdateAll',
Expand Down Expand Up @@ -323,6 +323,7 @@ module.exports = {
'(public) @ember-data/store RecordArray#update',
'(public) @ember-data/store RecordArrayManager#createAdapterPopulatedRecordArray',
'(public) @ember-data/store RecordArrayManager#createRecordArray',
'(public) @ember-data/store RecordArrayManager#getRecordArraysForIdentifier',
'(public) @ember-data/store RecordArrayManager#liveRecordArrayFor',
'(public) @ember-data/store RecordArrayManager#unregisterRecordArray',
'(public) @ember-data/store RecordReference#id',
Expand Down
89 changes: 67 additions & 22 deletions packages/-ember-data/tests/integration/record-array-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

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

let store, manager;

Expand Down Expand Up @@ -100,24 +102,48 @@ module('integration/record_array_manager', function(hooks) {

assert.equal(allSummary.called.length, 0, 'initial: no calls to all.willDestroy');
assert.equal(adapterPopulatedSummary.called.length, 0, 'initial: no calls to adapterPopulated.willDestroy');
assert.equal(
internalPersonModel._recordArrays.size,
1,
'initial: expected the person to be a member of 1 recordArrays'
);
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
1,
'initial: expected the person to be a member of 1 recordArrays'
);
} else {
assert.equal(
internalPersonModel._recordArrays.size,
1,
'initial: expected the person to be a member of 1 recordArrays'
);
}
assert.equal('person' in manager._liveRecordArrays, true, 'initial: we have a live array for person');

all.destroy();
await settled();

assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of 1 recordArrays');
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
0,
'expected the person to be a member of no recordArrays'
);
} else {
assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of no recordArrays');
}
assert.equal(allSummary.called.length, 1, 'all.willDestroy called once');
assert.equal('person' in manager._liveRecordArrays, false, 'no longer have a live array for person');

manager.destroy();
await settled();

assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of no recordArrays');
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.equal(
manager.getRecordArraysForIdentifier(internalPersonModel.identifier).size,
0,
'expected the person to be a member of no recordArrays'
);
} else {
assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of no recordArrays');
}
assert.equal(allSummary.called.length, 1, 'all.willDestroy still only called once');
assert.equal(adapterPopulatedSummary.called.length, 1, 'adapterPopulated.willDestroy called once');
});
Expand Down Expand Up @@ -243,23 +269,42 @@ module('integration/record_array_manager', function(hooks) {
});

test('createRecordArray with optional content', function(assert) {
let record = {};
let internalModel = {
_recordArrays: new OrderedSet(),
getRecord() {
return record;
},
};
let content = A([internalModel]);
let recordArray = manager.createRecordArray('foo', content);
let content;
let record;
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
record = store.push({
data: {
type: 'car',
id: '1',
attributes: {
make: 'BMC',
model: 'Mini Cooper',
},
},
});
content = A([recordIdentifierFor(record)]);
} else {
let internalModel = {
_recordArrays: new OrderedSet(),
getRecord() {
return record;
},
};

assert.equal(recordArray.modelName, 'foo');
assert.equal(recordArray.isLoaded, true);
assert.equal(recordArray.manager, manager);
assert.equal(recordArray.get('content'), content);
assert.deepEqual(recordArray.toArray(), [record]);
content = A([internalModel]);
}

let recordArray = manager.createRecordArray('foo', content);

assert.deepEqual(internalModel._recordArrays.toArray(), [recordArray]);
assert.equal(recordArray.modelName, 'foo', 'has modelName');
assert.equal(recordArray.isLoaded, true, 'isLoaded is true');
assert.equal(recordArray.manager, manager, 'recordArray has manager');
if (RECORD_ARRAY_MANAGER_IDENTIFIERS) {
assert.deepEqual(recordArray.get('content'), [recordIdentifierFor(record)], 'recordArray has content');
} else {
assert.equal(recordArray.get('content'), content);
}
assert.deepEqual(recordArray.toArray(), [record], 'toArray works');
});

test('liveRecordArrayFor always return the same array for a given type', function(assert) {
Expand Down
Loading