diff --git a/services/docstore/app/coffee/DocManager.coffee b/services/docstore/app/coffee/DocManager.coffee index e30370154e..e49e96f03f 100644 --- a/services/docstore/app/coffee/DocManager.coffee +++ b/services/docstore/app/coffee/DocManager.coffee @@ -84,8 +84,4 @@ module.exports = DocManager = DocManager.getDoc project_id, doc_id, { version: false }, (error, doc) -> return callback(error) if error? return callback new Errors.NotFoundError("No such project/doc to delete: #{project_id}/#{doc_id}") if !doc? - MongoManager.upsertIntoDocCollection project_id, doc_id, doc.lines, (error) -> - return callback(error) if error? - MongoManager.markDocAsDeleted doc_id, (error) -> - return callback(error) if error? - callback() + MongoManager.markDocAsDeleted project_id, doc_id, callback diff --git a/services/docstore/app/coffee/MongoManager.coffee b/services/docstore/app/coffee/MongoManager.coffee index e44c995490..d1c941e788 100644 --- a/services/docstore/app/coffee/MongoManager.coffee +++ b/services/docstore/app/coffee/MongoManager.coffee @@ -27,12 +27,13 @@ module.exports = MongoManager = db.docs.update _id: ObjectId(doc_id), update, {upsert: true}, callback - markDocAsDeleted: (doc_id, callback)-> - update = - $set: {} - update.$set["deleted"] = true - db.docs.update _id: ObjectId(doc_id), update, (err)-> - callback(err) + markDocAsDeleted: (project_id, doc_id, callback)-> + db.docs.update { + _id: ObjectId(doc_id), + project_id: ObjectId(project_id) + }, { + $set: { deleted: true } + }, callback markDocAsArchived: (doc_id, rev, callback)-> update = diff --git a/services/docstore/test/unit/coffee/DocManagerTests.coffee b/services/docstore/test/unit/coffee/DocManagerTests.coffee index 58f26abaf3..109c36a2b2 100644 --- a/services/docstore/test/unit/coffee/DocManagerTests.coffee +++ b/services/docstore/test/unit/coffee/DocManagerTests.coffee @@ -129,8 +129,7 @@ describe "DocManager", -> @lines = ["mock", "doc", "lines"] @rev = 77 @DocManager.getDoc = sinon.stub().callsArgWith(3, null, {lines: @lines, rev:@rev}) - @MongoManager.upsertIntoDocCollection = sinon.stub().callsArg(3) - @MongoManager.markDocAsDeleted = sinon.stub().callsArg(1) + @MongoManager.markDocAsDeleted = sinon.stub().callsArg(2) @DocManager.deleteDoc @project_id, @doc_id, @callback it "should get the doc", -> @@ -138,14 +137,9 @@ describe "DocManager", -> .calledWith(@project_id, @doc_id) .should.equal true - it "should update the doc lines", -> - @MongoManager.upsertIntoDocCollection - .calledWith(@project_id, @doc_id, @lines) - .should.equal true - it "should mark doc as deleted", -> @MongoManager.markDocAsDeleted - .calledWith(@doc_id) + .calledWith(@project_id, @doc_id) .should.equal true it "should return the callback", -> @@ -154,11 +148,8 @@ describe "DocManager", -> describe "when the doc does not exist", -> beforeEach -> @DocManager.getDoc = sinon.stub().callsArgWith(3, null, null) - @MongoManager.upsertIntoDocCollection = sinon.stub() @DocManager.deleteDoc @project_id, @doc_id, @callback - it "should not try to insert a deleted doc", -> - @MongoManager.upsertIntoDocCollection.called.should.equal false it "should return a NotFoundError", -> @callback diff --git a/services/docstore/test/unit/coffee/MongoManagerTests.coffee b/services/docstore/test/unit/coffee/MongoManagerTests.coffee index 54a352417a..cf1479a880 100644 --- a/services/docstore/test/unit/coffee/MongoManagerTests.coffee +++ b/services/docstore/test/unit/coffee/MongoManagerTests.coffee @@ -76,15 +76,15 @@ describe "MongoManager", -> @db.docs.update = sinon.stub().callsArgWith(2, @stubbedErr) @oldRev = 77 - it "should process the update", (done)-> - @MongoManager.markDocAsDeleted @doc_id, (err)=> + it "should process the update", (done) -> + @MongoManager.markDocAsDeleted @project_id, @doc_id, (err)=> args = @db.docs.update.args[0] - assert.deepEqual args[0], {_id: ObjectId(@doc_id)} + assert.deepEqual args[0], {_id: ObjectId(@doc_id), project_id: ObjectId(@project_id)} assert.equal args[1]["$set"]["deleted"], true done() it "should return the error", (done)-> - @MongoManager.markDocAsDeleted @doc_id, (err)=> + @MongoManager.markDocAsDeleted @project_id, @doc_id, (err)=> err.should.equal @stubbedErr done()