Split lines on Windows line endings too
This commit is contained in:
@@ -29,113 +29,74 @@ describe "ShareJsUpdateManager", ->
|
||||
@ShareJsUpdateManager.getNewShareJsModel = sinon.stub().returns(@model)
|
||||
@ShareJsUpdateManager._listenForOps = sinon.stub()
|
||||
@ShareJsUpdateManager.removeDocFromCache = sinon.stub().callsArg(1)
|
||||
@updates = [
|
||||
{p: 4, t: "foo"}
|
||||
{p: 6, t: "bar"}
|
||||
]
|
||||
@updatedDocLines = ["one", "two"]
|
||||
|
||||
describe "with a text document", ->
|
||||
beforeEach ->
|
||||
@updates = [
|
||||
{p: 4, t: "foo"}
|
||||
{p: 6, t: "bar"}
|
||||
]
|
||||
@updatedDocLines = ["one", "two"]
|
||||
describe "successfully", ->
|
||||
beforeEach (done) ->
|
||||
@model.getSnapshot.callsArgWith(1, null, {snapshot: @updatedDocLines.join("\n"), v: @version})
|
||||
@ShareJsUpdateManager.applyUpdates @project_id, @doc_id, @updates, (err, docLines, version) =>
|
||||
@callback(err, docLines, version)
|
||||
done()
|
||||
|
||||
describe "successfully", ->
|
||||
beforeEach (done) ->
|
||||
@model.getSnapshot.callsArgWith(1, null, {snapshot: @updatedDocLines.join("\n"), v: @version})
|
||||
@ShareJsUpdateManager.applyUpdates @project_id, @doc_id, @updates, (err, docLines, version) =>
|
||||
@callback(err, docLines, version)
|
||||
done()
|
||||
it "should create a new ShareJs model", ->
|
||||
@ShareJsUpdateManager.getNewShareJsModel
|
||||
.called.should.equal true
|
||||
|
||||
it "should create a new ShareJs model", ->
|
||||
@ShareJsUpdateManager.getNewShareJsModel
|
||||
.called.should.equal true
|
||||
it "should listen for ops on the model", ->
|
||||
@ShareJsUpdateManager._listenForOps
|
||||
.calledWith(@model)
|
||||
.should.equal true
|
||||
|
||||
it "should listen for ops on the model", ->
|
||||
@ShareJsUpdateManager._listenForOps
|
||||
.calledWith(@model)
|
||||
.should.equal true
|
||||
it "should send each update to ShareJs", ->
|
||||
for update in @updates
|
||||
@model.applyOp
|
||||
.calledWith("#{@project_id}:#{@doc_id}", update).should.equal true
|
||||
|
||||
it "should send each update to ShareJs", ->
|
||||
for update in @updates
|
||||
@model.applyOp
|
||||
.calledWith("#{@project_id}:#{@doc_id}", update).should.equal true
|
||||
it "should get the updated doc lines", ->
|
||||
@model.getSnapshot
|
||||
.calledWith("#{@project_id}:#{@doc_id}")
|
||||
.should.equal true
|
||||
|
||||
it "should get the updated doc lines", ->
|
||||
@model.getSnapshot
|
||||
.calledWith("#{@project_id}:#{@doc_id}")
|
||||
.should.equal true
|
||||
it "should return the updated doc lines", ->
|
||||
@callback.calledWith(null, @updatedDocLines, @version).should.equal true
|
||||
|
||||
it "should return the updated doc lines", ->
|
||||
@callback.calledWith(null, @updatedDocLines, @version).should.equal true
|
||||
describe "when applyOp fails", ->
|
||||
beforeEach (done) ->
|
||||
@error = new Error("Something went wrong")
|
||||
@ShareJsUpdateManager._sendError = sinon.stub()
|
||||
@model.applyOp = sinon.stub().callsArgWith(2, @error)
|
||||
@ShareJsUpdateManager.applyUpdates @project_id, @doc_id, @updates, (err, docLines, version) =>
|
||||
@callback(err, docLines, version)
|
||||
done()
|
||||
|
||||
describe "when applyOp fails", ->
|
||||
beforeEach (done) ->
|
||||
@error = new Error("Something went wrong")
|
||||
@ShareJsUpdateManager._sendError = sinon.stub()
|
||||
@model.applyOp = sinon.stub().callsArgWith(2, @error)
|
||||
@ShareJsUpdateManager.applyUpdates @project_id, @doc_id, @updates, (err, docLines, version) =>
|
||||
@callback(err, docLines, version)
|
||||
done()
|
||||
it "should call sendError with the error", ->
|
||||
@ShareJsUpdateManager._sendError
|
||||
.calledWith(@project_id, @doc_id, @error)
|
||||
.should.equal true
|
||||
|
||||
it "should call sendError with the error", ->
|
||||
@ShareJsUpdateManager._sendError
|
||||
.calledWith(@project_id, @doc_id, @error)
|
||||
.should.equal true
|
||||
it "should call the callback with the error", ->
|
||||
@callback.calledWith(@error).should.equal true
|
||||
|
||||
it "should call the callback with the error", ->
|
||||
@callback.calledWith(@error).should.equal true
|
||||
describe "when getSnapshot fails", ->
|
||||
beforeEach (done) ->
|
||||
@error = new Error("Something went wrong")
|
||||
@ShareJsUpdateManager._sendError = sinon.stub()
|
||||
@model.getSnapshot.callsArgWith(1, @error)
|
||||
@ShareJsUpdateManager.applyUpdates @project_id, @doc_id, @updates, (err, docLines, version) =>
|
||||
@callback(err, docLines, version)
|
||||
done()
|
||||
|
||||
describe "when getSnapshot fails", ->
|
||||
beforeEach (done) ->
|
||||
@error = new Error("Something went wrong")
|
||||
@ShareJsUpdateManager._sendError = sinon.stub()
|
||||
@model.getSnapshot.callsArgWith(1, @error)
|
||||
@ShareJsUpdateManager.applyUpdates @project_id, @doc_id, @updates, (err, docLines, version) =>
|
||||
@callback(err, docLines, version)
|
||||
done()
|
||||
it "should call sendError with the error", ->
|
||||
@ShareJsUpdateManager._sendError
|
||||
.calledWith(@project_id, @doc_id, @error)
|
||||
.should.equal true
|
||||
|
||||
it "should call sendError with the error", ->
|
||||
@ShareJsUpdateManager._sendError
|
||||
.calledWith(@project_id, @doc_id, @error)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with the error", ->
|
||||
@callback.calledWith(@error).should.equal true
|
||||
|
||||
describe "with a JSON document", ->
|
||||
beforeEach ->
|
||||
@updates = [
|
||||
{p: ["lines", 0], dl: { foo: "bar "}}
|
||||
]
|
||||
@docLines = [text: "one", text: "two"]
|
||||
|
||||
describe "successfully", ->
|
||||
beforeEach (done) ->
|
||||
@model.getSnapshot.callsArgWith(1, null, {snapshot: {lines: @docLines}, v: @version})
|
||||
@ShareJsUpdateManager.applyUpdates @project_id, @doc_id, @updates, (err, docLines, version) =>
|
||||
@callback(err, docLines, version)
|
||||
done()
|
||||
|
||||
it "should create a new ShareJs model", ->
|
||||
@ShareJsUpdateManager.getNewShareJsModel
|
||||
.called.should.equal true
|
||||
|
||||
it "should listen for ops on the model", ->
|
||||
@ShareJsUpdateManager._listenForOps
|
||||
.calledWith(@model)
|
||||
.should.equal true
|
||||
|
||||
it "should send each update to ShareJs", ->
|
||||
for update in @updates
|
||||
@model.applyOp
|
||||
.calledWith("#{@project_id}:#{@doc_id}", update).should.equal true
|
||||
|
||||
it "should get the updated doc lines", ->
|
||||
@model.getSnapshot
|
||||
.calledWith("#{@project_id}:#{@doc_id}")
|
||||
.should.equal true
|
||||
|
||||
it "should return the updated doc lines", ->
|
||||
@callback.calledWith(null, @docLines, @version).should.equal true
|
||||
it "should call the callback with the error", ->
|
||||
@callback.calledWith(@error).should.equal true
|
||||
|
||||
describe "_listenForOps", ->
|
||||
beforeEach ->
|
||||
|
||||
Reference in New Issue
Block a user