Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] reset previously failed linked async belongs-to now works #7554

Merged
merged 6 commits into from
May 27, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,41 @@ module('async belongs-to rendering tests', function (hooks) {
}
});
});

test('Can reset a previously failed linked async belongs-to', async function (assert) {
assert.expect(4);
let people = makePeopleWithRelationshipData();
let sedona = store.push({
data: people.dict['6:has-linked-parent'],
});

adapter.setupPayloads(assert, [new ServerError([], 'person not found'), new ServerError([], 'person not found')]);

// render
this.set('sedona', sedona);

let originalOnError = Ember.onerror;
Ember.onerror = function (e) {
assert.ok(true, 'Rejects the first time');
};

await render(hbs`
<p>{{sedona.parent.name}}</p>
`);

const newParent = store.createRecord('person', { name: 'New Person' });
sedona.set('parent', newParent);
await settled();
assert.equal(
this.element.textContent.trim(),
'New Person',
'after resetting to a new record, shows new content on page'
);
newParent.unloadRecord();
await settled();
assert.equal(this.element.textContent.trim(), '', 'after unloading the record it shows no content on page');
sedona.reload();
await settled();
Ember.onerror = originalOnError;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export default function replaceRelatedRecord(graph: Graph, op: ReplaceRelatedRec
relationship[prop] = op.value;
state.hasReceivedData = true;
state.isEmpty = op.value === null;
state.isStale = false;
state.hasFailedLoadAttempt = false;

if (op.value) {
if (definition.type !== op.value.type) {
Expand Down