check that element being inserted has an _id

This commit is contained in:
Henry Oswald 2016-03-15 11:29:59 +00:00
parent f24bc2c501
commit ba9bc3a2e8
2 changed files with 8 additions and 1 deletions

View file

@ -501,7 +501,7 @@ module.exports = ProjectEntityHandler =
elementType = "fileRefs"
return elementType
if !element?
if !element? or !element._id?
e = new Error("no element passed to be inserted")
logger.err project_id:project._id, folder_id:folder_id, element:element, type:type, "failed trying to insert element as it was null"
return callback(e)

View file

@ -1048,6 +1048,13 @@ describe 'ProjectEntityHandler', ->
@projectLocator.findElement.args[0][0].element_id.should.equal @project.rootFolder[0]._id
done()
it "should error if the element has no _id", (done)->
doc =
name:"something"
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
@ProjectModel.update.called.should.equal false
done()
describe "_countElements", ->