Skip to content

Commit

Permalink
failing test for relationships not updating when null data returned
Browse files Browse the repository at this point in the history
This adds a failing test that a relationship should disassociate records
on both sides of the relationship when a payload explicitly returns null
for the data of that relationship.
  • Loading branch information
fivetanley committed Apr 30, 2018
1 parent 55b4d6b commit 741fe77
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,77 @@ module("integration/relationship/belongs_to Belongs-To Relationships", {
}
});

test("returning a null relationship from payload sets the relationship to null on both sides", function(assert) {
env.registry.register('model:app', DS.Model.extend({
name: attr('string'),
team: belongsTo('team', { async: true }),
}));
env.registry.register('model:team', DS.Model.extend({
apps: hasMany('app', {async: true})
}));
run(() => {
env.store.push({
data: {
id: '1',
type: 'app',
relationships: {
team: {
data: {
id: '1',
type: 'team'
}
}
}
},
included: [
{
id: '1',
type: 'team',
relationships: {
apps: {
data: [{
id: '1',
type: 'app'
}]
}
}
}
]
});
});

const app = env.store.peekRecord('app', '1');
const team = env.store.peekRecord('team', '1');
assert.equal(app.get('team.id'), team.get('id'), 'sets team correctly on app');
assert.deepEqual(team.get('apps').toArray().mapBy('id'), ['1'], 'sets apps correctly on team');

env.adapter.shouldBackgroundReloadRecord = () => false;
env.adapter.updateRecord = (store, type, snapshot) => {
return RSVP.resolve({
data: {
id: '1',
type: 'app',
attributes: {
name: 'Hello'
},
relationships: {
team: {
data: null
}
}
}
});
};

return run(() => {
app.set('name', 'Hello');
return app.save().then(() => {
assert.equal(app.get('team.id'), null, 'team removed from app relationship');
assert.deepEqual(team.get('apps').toArray().mapBy('id'), [], 'app removed from team apps relationship');
});
});
});

test("The store can materialize a non loaded monomorphic belongsTo association", function(assert) {
assert.expect(1);

Expand Down

0 comments on commit 741fe77

Please sign in to comment.