Skip to content

Commit

Permalink
Added failing test for #5136.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley Workman authored and hjdivad committed Jan 11, 2018
1 parent 4c2eca6 commit bbe8b41
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/integration/records/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,3 +765,49 @@ test('after unloading a record, the record can be saved again immediately', func
store.createRecord('person').save();
});
});

test('after unloading a record, pushing a new copy will setup relatioonships', function (assert) {
const store = env.store;
const personData = {
data: {
type: 'person',
id: '1',
attributes: {
name: 'Adam Sunderland'
}
}
};
const carData = {
data: {
type: 'car',
id: '10',
attributes: {
make: 'VW',
model: 'Beetle'
},
relationships: {
person: {
data: { type: 'person', id: '1' }
}
}
}
};

function pushCar() {
store.push(Ember.copy(carData, true));
}

Ember.run(() => { store.push(personData) });

let adam = env.store.peekRecord('person', 1);
assert.equal(adam.get('cars.length'), 0, 'cars hasMany starts off empty');

Ember.run(() => pushCar());
assert.equal(adam.get('cars.length'), 1, 'pushing car setups inverse relationship');

Ember.run(() => adam.get('cars.firstObject').unloadRecord());
assert.equal(adam.get('cars.length'), 0, 'unloading car cleaned up hasMany');

Ember.run(() => pushCar());
assert.equal(adam.get('cars.length'), 1, 'pushing car again setups inverse relationship');
});

0 comments on commit bbe8b41

Please sign in to comment.