Doc is always one version ahead of latest op version

This commit is contained in:
James Allen 2014-03-05 16:31:38 +00:00
parent 3660253fd4
commit 2e1307bd82
3 changed files with 6 additions and 4 deletions

View file

@ -19,7 +19,7 @@ module.exports = DiffManager =
logger.log lines: lines, version: version, updates: updates, "got doc and updates" logger.log lines: lines, version: version, updates: updates, "got doc and updates"
lastUpdate = updates[0] lastUpdate = updates[0]
if lastUpdate? and lastUpdate.v != version if lastUpdate? and lastUpdate.v != version - 1
return callback new Error("latest update version, #{lastUpdate.v}, does not match doc version, #{version}") return callback new Error("latest update version, #{lastUpdate.v}, does not match doc version, #{version}")
updatesToApply = [] updatesToApply = []

View file

@ -49,7 +49,7 @@ describe "Getting a diff", ->
MockDocUpdaterApi.docs[@doc_id] = MockDocUpdaterApi.docs[@doc_id] =
lines: @lines lines: @lines
version: 6 version: 7
TrackChangesClient.pushRawUpdates @doc_id, @updates, (error) => TrackChangesClient.pushRawUpdates @doc_id, @updates, (error) =>
throw error if error? throw error if error?

View file

@ -44,7 +44,9 @@ describe "DiffManager", ->
describe "getDiff", -> describe "getDiff", ->
beforeEach -> beforeEach ->
@lines = [ "hello", "world" ] @lines = [ "hello", "world" ]
@version = 42 # Op versions are the version they were applied to, so doc is always one version
# ahead.s
@version = 43
@updates = [ @updates = [
{ op: "mock-4", v: 42, meta: { start_ts: new Date(@to.getTime() + 20)} } { op: "mock-4", v: 42, meta: { start_ts: new Date(@to.getTime() + 20)} }
{ op: "mock-3", v: 41, meta: { start_ts: new Date(@to.getTime() + 10)} } { op: "mock-3", v: 41, meta: { start_ts: new Date(@to.getTime() + 10)} }
@ -82,7 +84,7 @@ describe "DiffManager", ->
describe "with mismatching versions", -> describe "with mismatching versions", ->
beforeEach -> beforeEach ->
@version = 42 @version = 50
@updates = [ { op: "mock-1", v: 40 }, { op: "mock-1", v: 39 } ] @updates = [ { op: "mock-1", v: 40 }, { op: "mock-1", v: 39 } ]
@DiffManager.getLatestDocAndUpdates = sinon.stub().callsArgWith(4, null, @lines, @version, @updates) @DiffManager.getLatestDocAndUpdates = sinon.stub().callsArgWith(4, null, @lines, @version, @updates)
@DiffManager.getDiff @project_id, @doc_id, @from, @to, @callback @DiffManager.getDiff @project_id, @doc_id, @from, @to, @callback