Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
feat(entity): prevent accidental infinite loops
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 2cb95270793a5a9aaee351c59d0b8ca0ac2fbabf
Showing with 7 additions and 8 deletions.
  1. +2 −1 build/tasks/server.js
  2. +4 −0 src/entity.js
  3. +1 −7 test/entity.spec.js
@@ -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
});
});

@@ -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);
});
}
@@ -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();
});
});

0 comments on commit 2cb9527

Please sign in to comment.