Skip to content

Commit

Permalink
Add a failing test case
Browse files Browse the repository at this point in the history
Unloading a new record that is related to another record does not remove it from the relationship.
  • Loading branch information
Windvis committed Aug 23, 2023
1 parent f0dd0d4 commit 3ae43de
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/main/tests/integration/records/new-record-unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,41 @@ module('Integration | Records | New Record Unload', function (hooks) {
assert.strictEqual(people.length, 1, 'precond - one person left in the store');
});

test('Rolling Back Attributes on multiple New (related) Records unloads them safely', async function (assert) {
const store = this.owner.lookup('service:store');
let Pat = store.createRecord('person', { name: 'Patrick Wachter' });
let Matt = store.createRecord('person', { name: 'Matthew Seidel' });
const friends = Matt.hasMany('friends').value();
friends.push(Pat);
let people = store.peekAll('person');

assert.strictEqual(friends.length, 1, 'Matt has friends');
assert.strictEqual(people.length, 2, 'precond - two people records in the store');
assert.true(Matt.hasDirtyAttributes, 'precond - record has dirty attributes');
assert.true(Matt.isNew, 'precond - record is new');
assert.true(Pat.hasDirtyAttributes, 'precond - record has dirty attributes');
assert.true(Pat.isNew, 'precond - record is new');

Pat.rollbackAttributes();

assert.false(Pat.isDestroyed, 'record is not yet destroyed');
assert.true(Pat.isDestroying, 'record is destroying');
assert.strictEqual(friends.length, 0, 'Matt has no friends');
assert.strictEqual(people.length, 1, 'precond - one person left in the store');

await settled();

assert.true(Pat.isDestroyed, 'record is destroyed');
assert.true(Pat.isDestroying, 'record is destroying');
assert.strictEqual(friends.length, 0, 'Matt has no friends');
assert.strictEqual(people.length, 1, 'precond - one person left in the store');

Matt.rollbackAttributes();
assert.false(Matt.isDestroyed, 'record is not yet destroyed');
assert.true(Matt.isDestroying, 'record is destroying');
assert.strictEqual(people.length, 0, 'precond - no person left in the store');
});

test('Unload on a New Record unloads that record safely', async function (assert) {
const store = this.owner.lookup('service:store');
const Matt = store.push({
Expand Down

0 comments on commit 3ae43de

Please sign in to comment.