|
|
@@ -229,4 +229,69 @@ describe "RedisManager", ->
|
|
|
it "should remove the doc_id from the project set", ->
|
|
|
@rclient.srem
|
|
|
.calledWith("DocsIn:#{@project_id}", @doc_id)
|
|
|
- .should.equal true
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "getAndSetDoc", ->
|
|
|
+ beforeEach ->
|
|
|
+ @rclient.get = sinon.stub()
|
|
|
+ @rclient.lrange = sinon.stub()
|
|
|
+ @rclient.del = sinon.stub()
|
|
|
+ @rclient.set = sinon.stub()
|
|
|
+ @rclient.rpush = sinon.stub()
|
|
|
+ @rclient.exec = sinon.stub()
|
|
|
+ @rclient.exec.yields(null, [
|
|
|
+ @lines = '["mock","lines"]',
|
|
|
+ @version = 42,
|
|
|
+ @doc_ops = ["mock", "doc", "ops"],
|
|
|
+ @project_id = "mock-project-id"
|
|
|
+ ])
|
|
|
+ @RedisManager.getAndSetDoc @doc_id, @callback
|
|
|
+
|
|
|
+ it "should get the original values", ->
|
|
|
+ @rclient.get
|
|
|
+ .calledWith("doclines:#{@doc_id}")
|
|
|
+ .should.equal true
|
|
|
+ @rclient.get
|
|
|
+ .calledWith("DocVersion:#{@doc_id}")
|
|
|
+ .should.equal true
|
|
|
+ @rclient.get
|
|
|
+ .calledWith("ProjectId:#{@doc_id}")
|
|
|
+ .should.equal true
|
|
|
+ @rclient.lrange
|
|
|
+ .calledWith("DocOps:#{@doc_id}", 0, -1)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should set the doclines again", ->
|
|
|
+ @rclient.set
|
|
|
+ .calledWith("doclines:#{@doc_id}", @lines)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should set the DocVersion again", ->
|
|
|
+ @rclient.set
|
|
|
+ .calledWith("DocVersion:#{@doc_id}", @version)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should set the project id again", ->
|
|
|
+ @rclient.set
|
|
|
+ .calledWith("ProjectId:#{@doc_id}", @project_id)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ it "should set the doc ops again", ->
|
|
|
+ @rclient.del
|
|
|
+ .calledWith("DocOps:#{@doc_id}")
|
|
|
+ .should.equal true
|
|
|
+ @rclient.rpush
|
|
|
+ .calledWith("DocOps:#{@doc_id}", @doc_ops...)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
+ describe "getAndSetProject", ->
|
|
|
+ beforeEach ->
|
|
|
+ @rclient.smembers = sinon.stub()
|
|
|
+ @rclient.sadd = sinon.stub()
|
|
|
+ @rclient.smembers.withArgs("DocsIn:#{@project_id}").yields(null, @doc_ids = ["mock-doc-1", "mock-doc-2"])
|
|
|
+ @RedisManager.getAndSetProject @project_id, @callback
|
|
|
+
|
|
|
+ it "should set the doc ids again", ->
|
|
|
+ @rclient.sadd
|
|
|
+ .calledWith("DocsIn:#{@project_id}", @doc_ids...)
|
|
|
+ .should.equal true
|