|
@@ -567,7 +567,7 @@ describe('DocManager', function () {
|
|
|
ranges: this.originalRanges,
|
|
ranges: this.originalRanges,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.MongoManager.upsertIntoDocCollection = sinon.stub().callsArg(3)
|
|
|
|
|
|
|
+ this.MongoManager.upsertIntoDocCollection = sinon.stub().yields()
|
|
|
this.MongoManager.setDocVersion = sinon.stub().yields()
|
|
this.MongoManager.setDocVersion = sinon.stub().yields()
|
|
|
return (this.DocManager._getDoc = sinon.stub())
|
|
return (this.DocManager._getDoc = sinon.stub())
|
|
|
})
|
|
})
|
|
@@ -600,7 +600,9 @@ describe('DocManager', function () {
|
|
|
|
|
|
|
|
it('should upsert the document to the doc collection', function () {
|
|
it('should upsert the document to the doc collection', function () {
|
|
|
return this.MongoManager.upsertIntoDocCollection
|
|
return this.MongoManager.upsertIntoDocCollection
|
|
|
- .calledWith(this.project_id, this.doc_id, { lines: this.newDocLines })
|
|
|
|
|
|
|
+ .calledWith(this.project_id, this.doc_id, this.rev, {
|
|
|
|
|
+ lines: this.newDocLines,
|
|
|
|
|
+ })
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -631,7 +633,9 @@ describe('DocManager', function () {
|
|
|
|
|
|
|
|
it('should upsert the ranges', function () {
|
|
it('should upsert the ranges', function () {
|
|
|
return this.MongoManager.upsertIntoDocCollection
|
|
return this.MongoManager.upsertIntoDocCollection
|
|
|
- .calledWith(this.project_id, this.doc_id, { ranges: this.newRanges })
|
|
|
|
|
|
|
+ .calledWith(this.project_id, this.doc_id, this.rev, {
|
|
|
|
|
+ ranges: this.newRanges,
|
|
|
|
|
+ })
|
|
|
.should.equal(true)
|
|
.should.equal(true)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -842,7 +846,7 @@ describe('DocManager', function () {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- return describe('when the doc does not exist', function () {
|
|
|
|
|
|
|
+ describe('when the doc does not exist', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, null, null)
|
|
this.DocManager._getDoc = sinon.stub().callsArgWith(3, null, null, null)
|
|
|
return this.DocManager.updateDoc(
|
|
return this.DocManager.updateDoc(
|
|
@@ -857,7 +861,7 @@ describe('DocManager', function () {
|
|
|
|
|
|
|
|
it('should upsert the document to the doc collection', function () {
|
|
it('should upsert the document to the doc collection', function () {
|
|
|
return this.MongoManager.upsertIntoDocCollection
|
|
return this.MongoManager.upsertIntoDocCollection
|
|
|
- .calledWith(this.project_id, this.doc_id, {
|
|
|
|
|
|
|
+ .calledWith(this.project_id, this.doc_id, undefined, {
|
|
|
lines: this.newDocLines,
|
|
lines: this.newDocLines,
|
|
|
ranges: this.originalRanges,
|
|
ranges: this.originalRanges,
|
|
|
})
|
|
})
|
|
@@ -874,5 +878,46 @@ describe('DocManager', function () {
|
|
|
return this.callback.calledWith(null, true, 1).should.equal(true)
|
|
return this.callback.calledWith(null, true, 1).should.equal(true)
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ describe('when another update is racing', function () {
|
|
|
|
|
+ beforeEach(function (done) {
|
|
|
|
|
+ this.DocManager._getDoc = sinon.stub().yields(null, this.doc)
|
|
|
|
|
+ this.MongoManager.upsertIntoDocCollection
|
|
|
|
|
+ .onFirstCall()
|
|
|
|
|
+ .yields(new Errors.DocRevValueError())
|
|
|
|
|
+ this.MongoManager.upsertIntoDocCollection.onSecondCall().yields(null)
|
|
|
|
|
+ this.RangeManager.shouldUpdateRanges.returns(true)
|
|
|
|
|
+ this.callback.callsFake(done)
|
|
|
|
|
+ this.DocManager.updateDoc(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.doc_id,
|
|
|
|
|
+ this.newDocLines,
|
|
|
|
|
+ this.version + 1,
|
|
|
|
|
+ this.newRanges,
|
|
|
|
|
+ this.callback
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should upsert the doc twice', function () {
|
|
|
|
|
+ this.MongoManager.upsertIntoDocCollection.should.have.been.calledWith(
|
|
|
|
|
+ this.project_id,
|
|
|
|
|
+ this.doc_id,
|
|
|
|
|
+ this.rev,
|
|
|
|
|
+ {
|
|
|
|
|
+ ranges: this.newRanges,
|
|
|
|
|
+ lines: this.newDocLines,
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ this.MongoManager.upsertIntoDocCollection.should.have.been.calledTwice
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should update the version once', function () {
|
|
|
|
|
+ this.MongoManager.setDocVersion.should.have.been.calledOnce
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('should return the callback with the new rev', function () {
|
|
|
|
|
+ this.callback.should.have.been.calledWith(null, true, this.rev + 1)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|