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

This commit is contained in:
Henry Oswald 2015-02-27 14:50:08 +00:00
parent daf7c4f68e
commit 53480153e3
2 changed files with 22 additions and 1 deletions

View file

@ -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"

View file

@ -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)