Sfoglia il codice sorgente

fix DocumentUpdaterHandler.updateProjectStructure

Hayden Faulds 9 anni fa
parent
commit
bfd22899a0

+ 7 - 11
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
 

+ 15 - 0
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()
+