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

Merge branch 'master' into doc-collection-only

Conflicts:
	app/coffee/DocManager.coffee
Henry Oswald 11 лет назад
Родитель
Сommit
d59fb0d590

+ 5 - 2
services/docstore/app/coffee/DocManager.coffee

@@ -28,8 +28,11 @@ module.exports = DocManager =
 			if err?
 				logger.err project_id: project_id, doc_id: doc_id, err:err, "error getting document for update"
 				return callback(err)
-			
-			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 - not updating"
 				return callback null, false, doc?.rev
 			else

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

@@ -199,6 +199,20 @@ 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 = []
+				@MongoManager.findDoc = sinon.stub().callsArgWith(1, null, @doc)
+				@DocManager.updateDoc @project_id, @doc_id, @doc.lines, @callback
+
+			it "should upsert the document to the doc collection", ->
+				@MongoManager.upsertIntoDocCollection
+					.calledWith(@project_id, @doc_id,  @doc.lines)
+					.should.equal true	
+
+
 		describe "when the doc does not exist", ->
 			beforeEach ->
 				@MongoManager.findDoc = sinon.stub().callsArgWith(1, null, null, null)