-
-
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.
[BUGFIX] Octane: should not need to use get with model.id (#6829)
- Loading branch information
Showing
10 changed files
with
394 additions
and
37 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
10 changes: 7 additions & 3 deletions
10
packages/-ember-data/.ember-cli → packages/-ember-data/.ember-cli.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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
{ | ||
const { setEdition } = require('@ember/edition-utils'); | ||
|
||
setEdition('octane'); | ||
|
||
module.exports = { | ||
/** | ||
Ember CLI sends analytics information by default. The data is completely | ||
anonymous, but there are times when you might want to disable this behavior. | ||
Setting `disableAnalytics` to true will prevent any data from being sent. | ||
*/ | ||
"disableAnalytics": false | ||
} | ||
disableAnalytics: false, | ||
}; |
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
99 changes: 99 additions & 0 deletions
99
packages/-ember-data/tests/acceptance/tracking-model-id-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,99 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render, settled } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import Store from '@ember-data/store'; | ||
import Model, { attr } from '@ember-data/model'; | ||
import JSONAPIAdapter from '@ember-data/adapter/json-api'; | ||
import JSONAPISerializer from '@ember-data/serializer/json-api'; | ||
import Component from '@glimmer/component'; | ||
import { gte } from 'ember-compatibility-helpers'; | ||
import { has } from 'require'; | ||
import { resolve } from 'rsvp'; | ||
|
||
if (gte('3.13.0') && has('@glimmer/component')) { | ||
class Widget extends Model { | ||
@attr() name; | ||
|
||
get numericId() { | ||
return Number(this.id); | ||
} | ||
} | ||
|
||
class WidgetList extends Component { | ||
get sortedWidgets() { | ||
let { widgets } = this.args; | ||
|
||
return widgets.slice().sort((a, b) => b.numericId - a.numericId); | ||
} | ||
} | ||
|
||
let layout = hbs` | ||
<ul> | ||
{{#each this.sortedWidgets as |widget index|}} | ||
<li class="widget{{index}}"> | ||
<div class="id">ID: {{widget.id}}</div> | ||
<div class="numeric-id">Numeric ID: {{widget.numericId}}</div> | ||
<div class="name">Name: {{widget.name}}</div> | ||
<br/> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
`; | ||
|
||
class TestAdapter extends JSONAPIAdapter { | ||
createRecord() { | ||
return resolve({ | ||
data: { | ||
id: '4', | ||
type: 'widget', | ||
attributes: { | ||
name: 'Contraption', | ||
}, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
module('acceptance/tracking-model-id - tracking model id', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.beforeEach(function() { | ||
let { owner } = this; | ||
owner.register('service:store', Store); | ||
owner.register('model:widget', Widget); | ||
owner.register('component:widget-list', WidgetList); | ||
owner.register('template:components/widget-list', layout); | ||
owner.register('adapter:application', TestAdapter); | ||
owner.register('serializer:application', JSONAPISerializer); | ||
}); | ||
|
||
test("can track model id's without using get", async function(assert) { | ||
let store = this.owner.lookup('service:store'); | ||
store.createRecord('widget', { id: '1', name: 'Doodad' }); | ||
store.createRecord('widget', { id: '3', name: 'Gizmo' }); | ||
store.createRecord('widget', { id: '2', name: 'Gadget' }); | ||
this.widgets = store.peekAll('widget'); | ||
|
||
await render(hbs` | ||
<WidgetList @widgets={{this.widgets}} /> | ||
`); | ||
await settled(); | ||
|
||
assert.dom('ul>li+li+li').exists; | ||
assert.dom('ul>li.widget0>div.name').containsText('Gizmo'); | ||
assert.dom('ul>li.widget1>div.name').containsText('Gadget'); | ||
assert.dom('ul>li.widget2>div.name').containsText('Doodad'); | ||
|
||
let contraption = store.createRecord('widget', { name: 'Contraption' }); | ||
await contraption.save(); | ||
await settled(); | ||
|
||
assert.dom('ul>li+li+li+li').exists; | ||
assert.dom('ul>li.widget0>div.name').containsText('Contraption'); | ||
assert.dom('ul>li.widget1>div.name').containsText('Gizmo'); | ||
assert.dom('ul>li.widget2>div.name').containsText('Gadget'); | ||
assert.dom('ul>li.widget3>div.name').containsText('Doodad'); | ||
}); | ||
}); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/-ember-data/tests/dummy/config/optional-features.json
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"template-only-glimmer-components": true, | ||
"application-template-wrapper": false, | ||
"jquery-integration": false | ||
} |
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
Oops, something went wrong.