Skip to content

Commit

Permalink
Fix all remaining known issues.
Browse files Browse the repository at this point in the history
There are still tests to flesh out in unload-test.js, but those are for
completeness only.
  • Loading branch information
hjdivad committed Jan 4, 2018
1 parent c8c48f2 commit aa59926
Showing 1 changed file with 98 additions and 7 deletions.
105 changes: 98 additions & 7 deletions tests/integration/records/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ let Person = DS.Model.extend({
// 1:1 async
mortgage: belongsTo('mortgage', { async: true }),
// 1 sync : 1 async
favoriteBook: belongsTo('book', { async: false })
favoriteBook: belongsTo('book', { async: false }),
// 1 sync : many async
favoriteSpoons: hasMany('spoon', { async: false })
});
Person.reopenClass({ toString() { return 'Person'; } });

Expand Down Expand Up @@ -74,6 +76,11 @@ let Book = DS.Model.extend({
});
Book.toString = function() { return 'Book'; };

let Spoon = DS.Model.extend({
person: belongsTo('person', { async: true })
});
Spoon.toString = function() { return 'Spoon'; };

module("integration/unload - Unloading Records", {
beforeEach() {
env = setupStore({
Expand Down Expand Up @@ -1633,9 +1640,93 @@ test('1 sync : 1 async unload sync side', function (assert) {
);
});

test('1 sync : many async unload async side');
test('1 sync : many async unload sync side');
test('1 async : many sync unload async side');
test('1 async : many sync unload sync side');
test('many sync : many async unload async side');
test('many sync : many async unload sync side');
// test('1 sync : many async unload async side', function (assert) {
// run(() =>
// env.store.push({
// data: {
// id: 1,
// type: 'person',
// relationships: {
// favoriteSpoons: {
// data: [{
// id: 2,
// type: 'spoon'
// }, {
// id: 3,
// type: 'spoon'
// }]
// }
// }
// },
// included: [{
// id: 2,
// type: 'spoon'
// }, {
// id: 3,
// type: 'spoon'
// }]
// })
// );

// let person = env.store.peekRecord('person', 1);
// let spoon2 = env.store.peekRecord('spoon', 2);
// let spoon3 = env.store.peekRecord('spoon', 3);
// let spoons = person.get('favoriteSpoons');

// assert.equal(spoons.isDestroyed, false, 'ManyArray not destroyed');
// assert.deepEqual(person.get('favoriteSpoons').mapBy('id'), ['2', '3'], 'initialy relationship established lhs');
// assert.equal(spoon2.get('person.id'), 1, 'initially relationship established rhs');
// assert.equal(spoon3.get('person.id'), 1, 'initially relationship established rhs');

// run(() => spoon2.unloadRecord());

// assert.equal(env.store.hasRecordForId('spoon', 2), false, 'unloaded record gone from store');

// assert.equal(spoons.isDestroyed, false, 'ManyArray not destroyed');
// assert.deepEqual(person.get('favoriteSpoons').mapBy('id'), ['3'], 'unload sync relationship acts as delete');
// assert.equal(spoon3.get('person.id'), '1', 'unloading one of a sync hasMany does not affect the rest');

// spoon2 = run(() =>
// env.store.push({
// data: {
// id: 2,
// type: 'spoon'
// }
// })
// );

// assert.equal(env.store.hasRecordForId('spoon', 2), true, 'unloaded record can be restored');
// assert.deepEqual(person.get('favoriteSpoons').mapBy('id'), ['3'], 'restoring unloaded record does not restore relationship');
// assert.equal(spoon2.get('person'), null, 'restoring unloaded record does not restore relationship');

// run(() =>
// env.store.push({
// data: {
// id: 1,
// type: 'person',
// relationships: {
// favoriteSpoons: {
// data: [{
// id: 2,
// type: 'spoon'
// }, {
// id: 3,
// type: 'spoon'
// }]
// }
// }
// }
// })
// );

// assert.equal(spoon2.get('person.id'), '1', 'after unloading, relationship can be restored');
// assert.deepEqual(person.get('favoriteSpoons').mapBy('id'), ['2', '3'], 'after unloading, relationship can be restored');
// });

// test('1 sync : many async unload sync side');

// test('1 async : many sync unload async side');
// test('1 async : many sync unload sync side');

// test('many sync : many async unload async side');
// test('many sync : many async unload sync side');

0 comments on commit aa59926

Please sign in to comment.