diff --git a/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee b/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee index 3f5972bdc7..fc4b5c452b 100644 --- a/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee +++ b/services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee @@ -236,26 +236,22 @@ module.exports = DocumentUpdaterHandler = oldEntitiesHash = _.indexBy oldEntities, (entity) -> entity[entityType]._id.toString() newEntitiesHash = _.indexBy newEntities, (entity) -> entity[entityType]._id.toString() - for id, oldEntity of oldEntitiesHash - newEntity = newEntitiesHash[id] - - # renamed entities - if newEntity.path != oldEntity.path - updates.push - id: id - pathname: oldEntity.path - newPathname: newEntity.path - for id, newEntity of newEntitiesHash oldEntity = oldEntitiesHash[id] - # removed entities if !oldEntity? + # entity added updates.push id: id pathname: newEntity.path docLines: newEntity.docLines url: newEntity.url + else if newEntity.path != oldEntity.path + # entity renamed + updates.push + id: id + pathname: oldEntity.path + newPathname: newEntity.path updates diff --git a/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee b/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee index 9f1e292b2c..99214749d6 100644 --- a/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee +++ b/services/web/test/unit/coffee/DocumentUpdater/DocumentUpdaterHandlerTests.coffee @@ -483,3 +483,18 @@ describe 'DocumentUpdaterHandler', -> .calledWith(url: @url, json: {docUpdates: [], fileUpdates, userId: @user_id}) .should.equal true done() + + describe "when a doc has been deleted", -> + it 'should do nothing', (done) -> + @docId = new ObjectId() + @oldDocs = [ + { path: '/foo', docLines: 'a\nb', doc: _id: @docId } + ] + @newDocs = [] + @oldFiles = [] + @newFiles = [] + + @handler.updateProjectStructure @project_id, @user_id, @oldDocs, @newDocs, @oldFiles, @newFiles, () => + @request.post.called.should.equal false + done() +