 			@ShareJsUpdateManager.getNewShareJsModel = sinon.stub().returns(@model)
 			@ShareJsUpdateManager._listenForOps = sinon.stub()
 			@ShareJsUpdateManager.removeDocFromCache = sinon.stub().callsArg(1)
-			@update = {p: 4, t: "foo"}
-			@updatedDocLines = ["one", "two"]
 
 		describe "successfully", ->
 			beforeEach (done) ->
 				@model.getSnapshot.callsArgWith(1, null, {snapshot: @updatedDocLines.join("\n"), v: @version})
 				@model.db.appliedOps["#{@project_id}:#{@doc_id}"] = @appliedOps = ["mock-ops"]
-				@ShareJsUpdateManager.applyUpdate @project_id, @doc_id, @update, (err, docLines, version, appliedOps) =>
+				@ShareJsUpdateManager.applyUpdate @project_id, @doc_id, @update, @lines, @version, (err, docLines, version, appliedOps) =>
 					@callback(err, docLines, version, appliedOps)
 					done()
 
 			it "should create a new ShareJs model", ->
 				@ShareJsUpdateManager.getNewShareJsModel
-					.called.should.equal true
+					.calledWith(@project_id, @doc_id, @lines, @version)
+					.should.equal true
 
 			it "should listen for ops on the model", ->
 				@ShareJsUpdateManager._listenForOps

				@opData =
					op: {t: "foo", p: 1}
					meta: source: "bar"
				@rclient.publish = sinon.stub()
				@callback("#{@project_id}:#{@doc_id}", @opData)

			it "should publish the op to redis", ->
				@rclient.publish
					.calledWith("applied-ops", JSON.stringify(project_id: @project_id, doc_id: @doc_id, op: @opData))
					.should.equal true

	describe "_sendError", ->
		beforeEach ->
			@error_text = "Something went wrong"
			@rclient.publish = sinon.stub()
			@ShareJsUpdateManager._sendError(@project_id, @doc_id, new Error(@error_text))

		it "should publish the error to the redis stream", ->
			@rclient.publish
				.calledWith("applied-ops", JSON.stringify(project_id: @project_id, doc_id: @doc_id, error: @error_text))
				.should.equal true


				@error = new Error("Something went wrong")
				@ShareJsUpdateManager._sendError = sinon.stub()
				@model.applyOp = sinon.stub().callsArgWith(2, @error)
				@ShareJsUpdateManager.applyUpdate @project_id, @doc_id, @update, @lines, @version, (err, docLines, version) =>
					@callback(err, docLines, version)
					done()

