Skip to content

Commit

Permalink
[TEST] Added test for issue emberjs#7265 (Self-Referent Relationship …
Browse files Browse the repository at this point in the history
…in Save Response Blows Up Save).

Tests the case where a save-response returns a relationship that includes the self-id.
This passes in master, but is broken in 3.12 LTS
  • Loading branch information
davelindquist-egistix committed Aug 11, 2020
1 parent 78162a0 commit 4f8dc5e
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)'
let store;
setupTest(hooks);

class Company extends Model {
@belongsTo('company', { inverse: null, async: true })
parentCompany;
@attr()
name;
};

class Person extends Model {
@belongsTo('pet', { inverse: 'bestHuman', async: true })
bestDog;
Expand All @@ -44,7 +51,8 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)'
let { owner } = this;
owner.register('service:store', Store);
owner.register('model:person', Person);
owner.register('model:pet', Pet);
owner.register('model:pet', Pet);
owner.register('model:company', Company);
owner.register(
'serializer:application',
JSONAPISerializer.extend({
Expand Down Expand Up @@ -183,6 +191,34 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)'
assert.ok(pirate.get('bestHuman') === null, 'scene 3 - pirate no longer has Chris as best human');
assert.ok(bestDog === null, 'scene 3 - Chris has no best dog');
});

test("belongsTo saving with relationship that references yourself doesn't blow up", async function(assert) {
this.owner.register(
'adapter:company',
JSONAPIAdapter.extend({
createRecord(store, type, snapshot) {
return resolve({
data: {
type: 'company',
id: '123',
attributes: { name: 'Acme Corporation' },
relationships: {
parentCompany: {
data: { type: 'company', id: '123' }
},
},
},
});
}
})
);

let company = store.createRecord('company');
company.set('name', 'Acme Corporation');
company = await company.save();
assert.ok(company.id);
assert.equal(company.belongsTo('parentCompany').id(), company.id);
});
});

module('integration/relationship/belongs_to Belongs-To Relationships', function(hooks) {
Expand Down

0 comments on commit 4f8dc5e

Please sign in to comment.