add projectHistryId to project structure updates

This commit is contained in:
Hayden Faulds 2018-04-13 14:59:36 +01:00
parent a220794d32
commit 25c0be4eaa
10 changed files with 56 additions and 44 deletions

View file

@ -161,13 +161,13 @@ module.exports = DocumentManager =
return callback(error) if error? return callback(error) if error?
callback() callback()
renameDoc: (project_id, doc_id, user_id, update, _callback = (error) ->) -> renameDoc: (project_id, doc_id, user_id, update, projectHistoryId, _callback = (error) ->) ->
timer = new Metrics.Timer("docManager.updateProject") timer = new Metrics.Timer("docManager.updateProject")
callback = (args...) -> callback = (args...) ->
timer.done() timer.done()
_callback(args...) _callback(args...)
RedisManager.renameDoc project_id, doc_id, user_id, update, callback RedisManager.renameDoc project_id, doc_id, user_id, update, projectHistoryId, callback
getDocAndFlushIfOld: (project_id, doc_id, callback = (error, doc) ->) -> getDocAndFlushIfOld: (project_id, doc_id, callback = (error, doc) ->) ->
DocumentManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname, projectHistoryId, unflushedTime, alreadyLoaded) -> DocumentManager.getDoc project_id, doc_id, (error, lines, version, ranges, pathname, projectHistoryId, unflushedTime, alreadyLoaded) ->
@ -223,9 +223,9 @@ module.exports = DocumentManager =
UpdateManager = require "./UpdateManager" UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.deleteComment, project_id, doc_id, thread_id, callback UpdateManager.lockUpdatesAndDo DocumentManager.deleteComment, project_id, doc_id, thread_id, callback
renameDocWithLock: (project_id, doc_id, user_id, update, callback = (error) ->) -> renameDocWithLock: (project_id, doc_id, user_id, update, projectHistoryId, callback = (error) ->) ->
UpdateManager = require "./UpdateManager" UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.renameDoc, project_id, doc_id, user_id, update, callback UpdateManager.lockUpdatesAndDo DocumentManager.renameDoc, project_id, doc_id, user_id, update, projectHistoryId, callback
resyncDocContentsWithLock: (project_id, doc_id, callback = (error) ->) -> resyncDocContentsWithLock: (project_id, doc_id, callback = (error) ->) ->
UpdateManager = require "./UpdateManager" UpdateManager = require "./UpdateManager"

View file

@ -161,10 +161,10 @@ module.exports = HttpController =
updateProject: (req, res, next = (error) ->) -> updateProject: (req, res, next = (error) ->) ->
timer = new Metrics.Timer("http.updateProject") timer = new Metrics.Timer("http.updateProject")
project_id = req.params.project_id project_id = req.params.project_id
{userId, docUpdates, fileUpdates, version} = req.body {projectHistoryId, userId, docUpdates, fileUpdates, version} = req.body
logger.log {project_id, docUpdates, fileUpdates, version}, "updating project via http" logger.log {project_id, docUpdates, fileUpdates, version}, "updating project via http"
ProjectManager.updateProjectWithLocks project_id, userId, docUpdates, fileUpdates, version, (error) -> ProjectManager.updateProjectWithLocks project_id, projectHistoryId, userId, docUpdates, fileUpdates, version, (error) ->
timer.done() timer.done()
return next(error) if error? return next(error) if error?
logger.log project_id: project_id, "updated project via http" logger.log project_id: project_id, "updated project via http"

View file

@ -7,7 +7,7 @@ module.exports = ProjectHistoryRedisManager =
queueOps: (project_id, ops..., callback) -> queueOps: (project_id, ops..., callback) ->
rclient.rpush projectHistoryKeys.projectHistoryOps({project_id}), ops..., callback rclient.rpush projectHistoryKeys.projectHistoryOps({project_id}), ops..., callback
queueRenameEntity: (project_id, entity_type, entity_id, user_id, projectUpdate, callback) -> queueRenameEntity: (project_id, projectHistoryId, entity_type, entity_id, user_id, projectUpdate, callback) ->
projectUpdate = projectUpdate =
pathname: projectUpdate.pathname pathname: projectUpdate.pathname
new_pathname: projectUpdate.newPathname new_pathname: projectUpdate.newPathname
@ -15,6 +15,7 @@ module.exports = ProjectHistoryRedisManager =
user_id: user_id user_id: user_id
ts: new Date() ts: new Date()
version: projectUpdate.version version: projectUpdate.version
projectHistoryId: projectHistoryId
projectUpdate[entity_type] = entity_id projectUpdate[entity_type] = entity_id
logger.log {project_id, projectUpdate}, "queue rename operation to project-history" logger.log {project_id, projectUpdate}, "queue rename operation to project-history"
@ -22,7 +23,7 @@ module.exports = ProjectHistoryRedisManager =
ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback ProjectHistoryRedisManager.queueOps project_id, jsonUpdate, callback
queueAddEntity: (project_id, entity_type, entitiy_id, user_id, projectUpdate, callback = (error) ->) -> queueAddEntity: (project_id, projectHistoryId, entity_type, entitiy_id, user_id, projectUpdate, callback = (error) ->) ->
projectUpdate = projectUpdate =
pathname: projectUpdate.pathname pathname: projectUpdate.pathname
docLines: projectUpdate.docLines docLines: projectUpdate.docLines
@ -31,6 +32,7 @@ module.exports = ProjectHistoryRedisManager =
user_id: user_id user_id: user_id
ts: new Date() ts: new Date()
version: projectUpdate.version version: projectUpdate.version
projectHistoryId: projectHistoryId
projectUpdate[entity_type] = entitiy_id projectUpdate[entity_type] = entitiy_id
logger.log {project_id, projectUpdate}, "queue add operation to project-history" logger.log {project_id, projectUpdate}, "queue add operation to project-history"

View file

@ -105,7 +105,7 @@ module.exports = ProjectManager =
clearProjectState: (project_id, callback = (error) ->) -> clearProjectState: (project_id, callback = (error) ->) ->
RedisManager.clearProjectState project_id, callback RedisManager.clearProjectState project_id, callback
updateProjectWithLocks: (project_id, user_id, docUpdates, fileUpdates, version, _callback = (error) ->) -> updateProjectWithLocks: (project_id, projectHistoryId, user_id, docUpdates, fileUpdates, version, _callback = (error) ->) ->
timer = new Metrics.Timer("projectManager.updateProject") timer = new Metrics.Timer("projectManager.updateProject")
callback = (args...) -> callback = (args...) ->
timer.done() timer.done()
@ -120,11 +120,11 @@ module.exports = ProjectManager =
doc_id = projectUpdate.id doc_id = projectUpdate.id
projectUpdate.version = "#{project_version}.#{project_subversion++}" projectUpdate.version = "#{project_version}.#{project_subversion++}"
if projectUpdate.docLines? if projectUpdate.docLines?
ProjectHistoryRedisManager.queueAddEntity project_id, 'doc', doc_id, user_id, projectUpdate, (error, count) -> ProjectHistoryRedisManager.queueAddEntity project_id, projectHistoryId, 'doc', doc_id, user_id, projectUpdate, (error, count) ->
project_ops_length = count project_ops_length = count
cb(error) cb(error)
else else
DocumentManager.renameDocWithLock project_id, doc_id, user_id, projectUpdate, (error, count) -> DocumentManager.renameDocWithLock project_id, doc_id, user_id, projectUpdate, projectHistoryId, (error, count) ->
project_ops_length = count project_ops_length = count
cb(error) cb(error)
@ -132,11 +132,11 @@ module.exports = ProjectManager =
file_id = projectUpdate.id file_id = projectUpdate.id
projectUpdate.version = "#{project_version}.#{project_subversion++}" projectUpdate.version = "#{project_version}.#{project_subversion++}"
if projectUpdate.url? if projectUpdate.url?
ProjectHistoryRedisManager.queueAddEntity project_id, 'file', file_id, user_id, projectUpdate, (error, count) -> ProjectHistoryRedisManager.queueAddEntity project_id, projectHistoryId, 'file', file_id, user_id, projectUpdate, (error, count) ->
project_ops_length = count project_ops_length = count
cb(error) cb(error)
else else
ProjectHistoryRedisManager.queueRenameEntity project_id, 'file', file_id, user_id, projectUpdate, (error, count) -> ProjectHistoryRedisManager.queueRenameEntity project_id, projectHistoryId, 'file', file_id, user_id, projectUpdate, (error, count) ->
project_ops_length = count project_ops_length = count
cb(error) cb(error)

View file

@ -275,16 +275,16 @@ module.exports = RedisManager =
else else
callback null, docUpdateCount callback null, docUpdateCount
renameDoc: (project_id, doc_id, user_id, update, callback = (error) ->) -> renameDoc: (project_id, doc_id, user_id, update, projectHistoryId, callback = (error) ->) ->
RedisManager.getDoc project_id, doc_id, (error, lines, version) -> RedisManager.getDoc project_id, doc_id, (error, lines, version) ->
return callback(error) if error? return callback(error) if error?
if lines? and version? if lines? and version?
rclient.set keys.pathname(doc_id:doc_id), update.newPathname, (error) -> rclient.set keys.pathname(doc_id:doc_id), update.newPathname, (error) ->
return callback(error) if error? return callback(error) if error?
ProjectHistoryRedisManager.queueRenameEntity project_id, 'doc', doc_id, user_id, update, callback ProjectHistoryRedisManager.queueRenameEntity project_id, projectHistoryId, 'doc', doc_id, user_id, update, callback
else else
ProjectHistoryRedisManager.queueRenameEntity project_id, 'doc', doc_id, user_id, update, callback ProjectHistoryRedisManager.queueRenameEntity project_id, projectHistoryId, 'doc', doc_id, user_id, update, callback
clearUnflushedTime: (doc_id, callback = (error) ->) -> clearUnflushedTime: (doc_id, callback = (error) ->) ->
rclient.del keys.unflushedTime(doc_id:doc_id), callback rclient.del keys.unflushedTime(doc_id:doc_id), callback

View file

@ -25,6 +25,7 @@ describe "DocumentManager", ->
"./UpdateManager": @UpdateManager = {} "./UpdateManager": @UpdateManager = {}
"./RangesManager": @RangesManager = {} "./RangesManager": @RangesManager = {}
@project_id = "project-id-123" @project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@doc_id = "doc-id-123" @doc_id = "doc-id-123"
@user_id = 1234 @user_id = 1234
@callback = sinon.stub() @callback = sinon.stub()
@ -459,11 +460,11 @@ describe "DocumentManager", ->
describe "successfully", -> describe "successfully", ->
beforeEach -> beforeEach ->
@DocumentManager.renameDoc @project_id, @doc_id, @user_id, @update, @callback @DocumentManager.renameDoc @project_id, @doc_id, @user_id, @update, @projectHistoryId, @callback
it "should rename the document", -> it "should rename the document", ->
@RedisManager.renameDoc @RedisManager.renameDoc
.calledWith(@project_id, @doc_id, @user_id, @update) .calledWith(@project_id, @doc_id, @user_id, @update, @projectHistoryId)
.should.equal true .should.equal true
it "should call the callback", -> it "should call the callback", ->

View file

@ -509,23 +509,24 @@ describe "HttpController", ->
describe "updateProject", -> describe "updateProject", ->
beforeEach -> beforeEach ->
@projectHistoryId = "history-id-123"
@userId = "user-id-123" @userId = "user-id-123"
@docUpdates = sinon.stub() @docUpdates = sinon.stub()
@fileUpdates = sinon.stub() @fileUpdates = sinon.stub()
@version = 1234567 @version = 1234567
@req = @req =
body: {@userId, @docUpdates, @fileUpdates, @version} body: {@projectHistoryId, @userId, @docUpdates, @fileUpdates, @version}
params: params:
project_id: @project_id project_id: @project_id
describe "successfully", -> describe "successfully", ->
beforeEach -> beforeEach ->
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(5) @ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(6)
@HttpController.updateProject(@req, @res, @next) @HttpController.updateProject(@req, @res, @next)
it "should accept the change", -> it "should accept the change", ->
@ProjectManager.updateProjectWithLocks @ProjectManager.updateProjectWithLocks
.calledWith(@project_id, @userId, @docUpdates, @fileUpdates, @version) .calledWith(@project_id, @projectHistoryId, @userId, @docUpdates, @fileUpdates, @version)
.should.equal true .should.equal true
it "should return a successful No Content response", -> it "should return a successful No Content response", ->
@ -538,7 +539,7 @@ describe "HttpController", ->
describe "when an errors occurs", -> describe "when an errors occurs", ->
beforeEach -> beforeEach ->
@ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(5, new Error("oops")) @ProjectManager.updateProjectWithLocks = sinon.stub().callsArgWith(6, new Error("oops"))
@HttpController.updateProject(@req, @res, @next) @HttpController.updateProject(@req, @res, @next)
it "should call next with the error", -> it "should call next with the error", ->

View file

@ -8,6 +8,7 @@ tk = require "timekeeper"
describe "ProjectHistoryRedisManager", -> describe "ProjectHistoryRedisManager", ->
beforeEach -> beforeEach ->
@project_id = "project-id-123" @project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@user_id = "user-id-123" @user_id = "user-id-123"
@callback = sinon.stub() @callback = sinon.stub()
@rclient = {} @rclient = {}
@ -50,9 +51,10 @@ describe "ProjectHistoryRedisManager", ->
@rawUpdate = @rawUpdate =
pathname: @pathname = '/old' pathname: @pathname = '/old'
newPathname: @newPathname = '/new' newPathname: @newPathname = '/new'
version: @version = 2
@ProjectHistoryRedisManager.queueOps = sinon.stub() @ProjectHistoryRedisManager.queueOps = sinon.stub()
@ProjectHistoryRedisManager.queueRenameEntity @project_id, 'file', @file_id, @user_id, @rawUpdate, @callback @ProjectHistoryRedisManager.queueRenameEntity @project_id, @projectHistoryId, 'file', @file_id, @user_id, @rawUpdate, @callback
it "should queue an update", -> it "should queue an update", ->
update = update =
@ -61,6 +63,8 @@ describe "ProjectHistoryRedisManager", ->
meta: meta:
user_id: @user_id user_id: @user_id
ts: new Date() ts: new Date()
version: @version
projectHistoryId: @projectHistoryId
file: @file_id file: @file_id
@ProjectHistoryRedisManager.queueOps @ProjectHistoryRedisManager.queueOps
@ -75,10 +79,11 @@ describe "ProjectHistoryRedisManager", ->
@rawUpdate = @rawUpdate =
pathname: @pathname = '/old' pathname: @pathname = '/old'
docLines: @docLines = 'a\nb' docLines: @docLines = 'a\nb'
version: @version = 2
url: @url = 'filestore.example.com' url: @url = 'filestore.example.com'
@ProjectHistoryRedisManager.queueOps = sinon.stub() @ProjectHistoryRedisManager.queueOps = sinon.stub()
@ProjectHistoryRedisManager.queueAddEntity @project_id, 'doc', @doc_id, @user_id, @rawUpdate, @callback @ProjectHistoryRedisManager.queueAddEntity @project_id, @projectHistoryId, 'doc', @doc_id, @user_id, @rawUpdate, @callback
it "should queue an update", -> it "should queue an update", ->
update = update =
@ -88,6 +93,8 @@ describe "ProjectHistoryRedisManager", ->
meta: meta:
user_id: @user_id user_id: @user_id
ts: new Date() ts: new Date()
version: @version
projectHistoryId: @projectHistoryId
doc: @doc_id doc: @doc_id
@ProjectHistoryRedisManager.queueOps @ProjectHistoryRedisManager.queueOps

View file

@ -18,6 +18,7 @@ describe "ProjectManager", ->
done: sinon.stub() done: sinon.stub()
@project_id = "project-id-123" @project_id = "project-id-123"
@projectHistoryId = 'history-id-123'
@user_id = "user-id-123" @user_id = "user-id-123"
@version = 1234567 @version = 1234567
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false) @HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(false)
@ -27,7 +28,6 @@ describe "ProjectManager", ->
describe "updateProjectWithLocks", -> describe "updateProjectWithLocks", ->
describe "rename operations", -> describe "rename operations", ->
beforeEach -> beforeEach ->
@firstDocUpdate = @firstDocUpdate =
id: 1 id: 1
pathname: 'foo' pathname: 'foo'
@ -47,22 +47,22 @@ describe "ProjectManager", ->
describe "successfully", -> describe "successfully", ->
beforeEach -> beforeEach ->
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should rename the docs in the updates", -> it "should rename the docs in the updates", ->
firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"}) firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"})
secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"}) secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"})
@DocumentManager.renameDocWithLock @DocumentManager.renameDocWithLock
.calledWith(@project_id, @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion) .calledWith(@project_id, @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion, @projectHistoryId)
.should.equal true .should.equal true
@DocumentManager.renameDocWithLock @DocumentManager.renameDocWithLock
.calledWith(@project_id, @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion) .calledWith(@project_id, @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion, @projectHistoryId)
.should.equal true .should.equal true
it "should rename the files in the updates", -> it "should rename the files in the updates", ->
firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"}) firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"})
@ProjectHistoryRedisManager.queueRenameEntity @ProjectHistoryRedisManager.queueRenameEntity
.calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion) .calledWith(@project_id, @projectHistoryId, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
.should.equal true .should.equal true
it "should not flush the history", -> it "should not flush the history", ->
@ -77,7 +77,7 @@ describe "ProjectManager", ->
beforeEach -> beforeEach ->
@error = new Error('error') @error = new Error('error')
@DocumentManager.renameDocWithLock = sinon.stub().yields(@error) @DocumentManager.renameDocWithLock = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", -> it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true @callback.calledWith(@error).should.equal true
@ -86,7 +86,7 @@ describe "ProjectManager", ->
beforeEach -> beforeEach ->
@error = new Error('error') @error = new Error('error')
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields(@error) @ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", -> it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true @callback.calledWith(@error).should.equal true
@ -94,7 +94,7 @@ describe "ProjectManager", ->
describe "with enough ops to flush", -> describe "with enough ops to flush", ->
beforeEach -> beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true) @HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should flush the history", -> it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync @HistoryManager.flushProjectChangesAsync
@ -121,26 +121,26 @@ describe "ProjectManager", ->
describe "successfully", -> describe "successfully", ->
beforeEach -> beforeEach ->
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should add the docs in the updates", -> it "should add the docs in the updates", ->
firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"}) firstDocUpdateWithVersion = _.extend({}, @firstDocUpdate, {version: "#{@version}.0"})
secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"}) secondDocUpdateWithVersion = _.extend({}, @secondDocUpdate, {version: "#{@version}.1"})
@ProjectHistoryRedisManager.queueAddEntity.getCall(0) @ProjectHistoryRedisManager.queueAddEntity.getCall(0)
.calledWith(@project_id, 'doc', @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion) .calledWith(@project_id, @projectHistoryId, 'doc', @firstDocUpdate.id, @user_id, firstDocUpdateWithVersion)
.should.equal true .should.equal true
@ProjectHistoryRedisManager.queueAddEntity.getCall(1) @ProjectHistoryRedisManager.queueAddEntity.getCall(1)
.calledWith(@project_id, 'doc', @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion) .calledWith(@project_id, @projectHistoryId, 'doc', @secondDocUpdate.id, @user_id, secondDocUpdateWithVersion)
.should.equal true .should.equal true
it "should add the files in the updates", -> it "should add the files in the updates", ->
firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"}) firstFileUpdateWithVersion = _.extend({}, @firstFileUpdate, {version: "#{@version}.2"})
secondFileUpdateWithVersion = _.extend({}, @secondFileUpdate, {version: "#{@version}.3"}) secondFileUpdateWithVersion = _.extend({}, @secondFileUpdate, {version: "#{@version}.3"})
@ProjectHistoryRedisManager.queueAddEntity.getCall(2) @ProjectHistoryRedisManager.queueAddEntity.getCall(2)
.calledWith(@project_id, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion) .calledWith(@project_id, @projectHistoryId, 'file', @firstFileUpdate.id, @user_id, firstFileUpdateWithVersion)
.should.equal true .should.equal true
@ProjectHistoryRedisManager.queueAddEntity.getCall(3) @ProjectHistoryRedisManager.queueAddEntity.getCall(3)
.calledWith(@project_id, 'file', @secondFileUpdate.id, @user_id, secondFileUpdateWithVersion) .calledWith(@project_id, @projectHistoryId, 'file', @secondFileUpdate.id, @user_id, secondFileUpdateWithVersion)
.should.equal true .should.equal true
it "should not flush the history", -> it "should not flush the history", ->
@ -155,7 +155,7 @@ describe "ProjectManager", ->
beforeEach -> beforeEach ->
@error = new Error('error') @error = new Error('error')
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error) @ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", -> it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true @callback.calledWith(@error).should.equal true
@ -164,7 +164,7 @@ describe "ProjectManager", ->
beforeEach -> beforeEach ->
@error = new Error('error') @error = new Error('error')
@ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error) @ProjectHistoryRedisManager.queueAddEntity = sinon.stub().yields(@error)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should call the callback with the error", -> it "should call the callback with the error", ->
@callback.calledWith(@error).should.equal true @callback.calledWith(@error).should.equal true
@ -172,7 +172,7 @@ describe "ProjectManager", ->
describe "with enough ops to flush", -> describe "with enough ops to flush", ->
beforeEach -> beforeEach ->
@HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true) @HistoryManager.shouldFlushHistoryOps = sinon.stub().returns(true)
@ProjectManager.updateProjectWithLocks @project_id, @user_id, @docUpdates, @fileUpdates, @version, @callback @ProjectManager.updateProjectWithLocks @project_id, @projectHistoryId, @user_id, @docUpdates, @fileUpdates, @version, @callback
it "should flush the history", -> it "should flush the history", ->
@HistoryManager.flushProjectChangesAsync @HistoryManager.flushProjectChangesAsync

View file

@ -60,6 +60,7 @@ describe "RedisManager", ->
@doc_id = "doc-id-123" @doc_id = "doc-id-123"
@project_id = "project-id-123" @project_id = "project-id-123"
@projectHistoryId = "history-id-123"
@callback = sinon.stub() @callback = sinon.stub()
describe "getDoc", -> describe "getDoc", ->
@ -703,7 +704,7 @@ describe "RedisManager", ->
beforeEach -> beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, 'lines', 'version') @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, 'lines', 'version')
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields() @ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields()
@RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @callback @RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @projectHistoryId, @callback
it "update the cached pathname", -> it "update the cached pathname", ->
@rclient.set @rclient.set
@ -712,19 +713,19 @@ describe "RedisManager", ->
it "should queue an update", -> it "should queue an update", ->
@ProjectHistoryRedisManager.queueRenameEntity @ProjectHistoryRedisManager.queueRenameEntity
.calledWithExactly(@project_id, 'doc', @doc_id, @userId, @update, @callback) .calledWithExactly(@project_id, @projectHistoryId, 'doc', @doc_id, @userId, @update, @callback)
.should.equal true .should.equal true
describe "the document is not cached in redis", -> describe "the document is not cached in redis", ->
beforeEach -> beforeEach ->
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, null, null) @RedisManager.getDoc = sinon.stub().callsArgWith(2, null, null, null)
@ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields() @ProjectHistoryRedisManager.queueRenameEntity = sinon.stub().yields()
@RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @callback @RedisManager.renameDoc @project_id, @doc_id, @userId, @update, @projectHistoryId, @callback
it "does not update the cached pathname", -> it "does not update the cached pathname", ->
@rclient.set.called.should.equal false @rclient.set.called.should.equal false
it "should queue an update", -> it "should queue an update", ->
@ProjectHistoryRedisManager.queueRenameEntity @ProjectHistoryRedisManager.queueRenameEntity
.calledWithExactly(@project_id, 'doc', @doc_id, @userId, @update, @callback) .calledWithExactly(@project_id, @projectHistoryId, 'doc', @doc_id, @userId, @update, @callback)
.should.equal true .should.equal true