Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(entity): prevent accidental infinite loops
Browse files Browse the repository at this point in the history
fixed tests. server needs to return an id on saving.  since it'll make it too complicated to also return fake associated entity ids, the test got simplified there
  • Loading branch information
doktordirk committed Jul 12, 2016
1 parent e959589 commit 2cb9527
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion build/tasks/server.js
Expand Up @@ -14,7 +14,8 @@ app.all('*', function(req, res) {
access_token: req.body.access_token,
method: req.method,
contentType: req.header('content-type'),
Authorization: req.header('Authorization')
Authorization: req.header('Authorization'),
id: 667
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/entity.js
Expand Up @@ -171,6 +171,10 @@ export class Entity {
if (!relation || relation.type !== 'entity') {
// Many relation, create and then link.
return entity.save().then(() => {
if (entity.isNew()) {
throw new Error('Entity did not return return an id on saving.');
}

return this.addCollectionAssociation(entity, property);
});
}
Expand Down
8 changes: 1 addition & 7 deletions test/entity.spec.js
Expand Up @@ -236,13 +236,7 @@ describe('Entity', function() {
});

parentEntity.save().then(response => {
let idBar = response.bar.id;
let idParent = response.id;

expect(typeof idParent).toEqual('number');
expect(typeof idBar).toEqual('number');

expect(response).toEqual({bar: {baby: 'steps', id: idBar}, test: 'case', id: idParent});
expect(response.body).toEqual({bar: {baby: 'steps'}, test: 'case'});
done();
});
});
Expand Down

0 comments on commit 2cb9527

Please sign in to comment.