From 53480153e385107c42165189bec5fbe3b6d8fe47 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 27 Feb 2015 14:50:08 +0000 Subject: [PATCH] if the doc has no lines then it is new and needs to be written --- .../docstore/app/coffee/DocManager.coffee | 4 +++- .../test/unit/coffee/DocManagerTests.coffee | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/services/docstore/app/coffee/DocManager.coffee b/services/docstore/app/coffee/DocManager.coffee index 49d34a7399..a8a5c0c01f 100644 --- a/services/docstore/app/coffee/DocManager.coffee +++ b/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" diff --git a/services/docstore/test/unit/coffee/DocManagerTests.coffee b/services/docstore/test/unit/coffee/DocManagerTests.coffee index cf4f76f0f8..1e4050ed3d 100644 --- a/services/docstore/test/unit/coffee/DocManagerTests.coffee +++ b/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)