-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* deactivate broken partner tests * feat: autotracking for reference id access (#7796) * feat: autotracking for reference id access * ensure references are torn down * fix build * add dep * add to deps * fix invalid json:api support and add valid json:api support * autotracking tests and cleanup * fix test failure, add comment * skip tests when feature not available * update test and fix lid reflection (#7800) * update test and fix lid reflection * remove debugger * fix ff off branch * add test and fix push of duplicate identifiers to a relationship (#7801) * add test + fix for chained async has many (#7691) * [bugfix]: fix for chained async has many * add fix and update tests * remove console.logs * make work with flags off * fix test for lts Co-authored-by: Chris Thoburn <[email protected]> * Fix: assign unknown properties in init after initialization is finished to ensure proper setup timing (#7771) * Add failing test case which illustrates the createRecord bug createRecord crashes when a setter which sets an attribute is involved in the createRecord. * update test location and add fix Co-authored-by: Chris Thoburn <[email protected]> * fix: A(PromiseManyArray) should have no-effect (#7802) Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]> Co-authored-by: Sylvain Mina <[email protected]> Co-authored-by: Andrey Fel <[email protected]>
- Loading branch information
1 parent
c5e6a0a
commit bb0f036
Showing
32 changed files
with
1,018 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,25 @@ module('Store.createRecord() coverage', function (hooks) { | |
store = owner.lookup('service:store'); | ||
}); | ||
|
||
test("createRecord doesn't crash when setter is involved", async function (assert) { | ||
class User extends Model { | ||
@attr() email; | ||
|
||
get name() { | ||
return this.email ? this.email.substring(0, this.email.indexOf('@')) : ''; | ||
} | ||
|
||
set name(value) { | ||
this.email = `${value.toLowerCase()}@ember.js`; | ||
} | ||
} | ||
this.owner.register(`model:user`, User); | ||
const store = this.owner.lookup('service:store'); | ||
|
||
const user = store.createRecord('user', { name: 'Robert' }); | ||
assert.strictEqual(user.email, '[email protected]'); | ||
}); | ||
|
||
test('unloading a newly created a record with a sync belongsTo relationship', async function (assert) { | ||
let chris = store.push({ | ||
data: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
packages/-ember-data/tests/integration/references/autotracking-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import EmberObject from '@ember/object'; | ||
import { getRootElement, render } from '@ember/test-helpers'; | ||
import settled from '@ember/test-helpers/settled'; | ||
|
||
import hbs from 'htmlbars-inline-precompile'; | ||
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' } }; | ||
} | ||
} | ||
); | ||
owner.register( | ||
'serializer:user', | ||
class extends EmberObject { | ||
normalizeResponse(_, __, data) { | ||
return data; | ||
} | ||
} | ||
); | ||
|
||
user = store.push({ | ||
data: { | ||
type: 'user', | ||
id: '1', | ||
attributes: { | ||
name: 'Chris', | ||
}, | ||
relationships: { | ||
bestFriend: { | ||
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' } }, | ||
], | ||
}); | ||
}); | ||
|
||
test('BelongsToReference.id() is autotracked', async function (assert) { | ||
class TestContext { | ||
user = user; | ||
|
||
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'); | ||
}); | ||
|
||
test('HasManyReference.ids() is autotracked', async function (assert) { | ||
class TestContext { | ||
user = user; | ||
|
||
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'); | ||
}); | ||
|
||
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; | ||
|
||
get id() { | ||
return this.user.id(); | ||
} | ||
} | ||
|
||
const testContext = new TestContext(); | ||
this.set('context', testContext); | ||
|
||
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'); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.