Просмотр исходного кода

if the doc has no lines then it is new and needs to be written

Henry Oswald 11 лет назад
Родитель
Сommit
53480153e3

+ 3 - 1
services/docstore/app/coffee/DocManager.coffee

@@ -34,7 +34,9 @@ module.exports = DocManager =
 			return callback(error) if error?
 			return callback new Errors.NotFoundError("No such project/doc to update: #{project_id}/#{doc_id}") if !doc? or !mongoPath?
 
-			if _.isEqual(doc.lines, lines)
+			isNewDoc = lines.length == 0
+			linesAreSame =  _.isEqual(doc.lines, lines)
+			if linesAreSame and !isNewDoc
 				logger.log {
 					project_id: project_id, doc_id: doc_id, rev: doc.rev
 				}, "doc lines have not changed"

+ 19 - 0
services/docstore/test/unit/coffee/DocManagerTests.coffee

@@ -246,6 +246,25 @@ describe "DocManager", ->
 			it "should return the callback with the existing rev", ->
 				@callback.calledWith(null, false, @rev).should.equal true
 
+
+		describe "when the doc lines are an empty array", ->
+			beforeEach ->
+
+				@doc.lines = []
+				@DocManager.getDoc = sinon.stub().callsArgWith(2, null, @doc, @mongoPath)
+				@DocManager.updateDoc @project_id, @doc_id, @doc.lines, @callback
+
+			it "should still upsert the doc even though the lines are the same", ->
+				@MongoManager.updateDoc
+					.calledWith(@project_id, @mongoPath, [])
+					.should.equal true
+
+			it "should upsert the document to the doc collection", ->
+				@MongoManager.upsertIntoDocCollection
+					.calledWith(@project_id, @doc_id, [], @rev)
+					.should.equal true	
+
+
 		describe "when the doc does not exist", ->
 			beforeEach ->
 				@DocManager.getDoc = sinon.stub().callsArgWith(2, null, null, null)