Merge branch 'tpds-cleanup'

This commit is contained in:
Henry Oswald 2015-04-23 10:06:26 +01:00
commit 6669884f44
2 changed files with 10 additions and 2 deletions

View file

@ -19,11 +19,16 @@ module.exports =
if element?
elementId = element._id
self.p.writeStreamToDisk project_id, elementId, updateRequest, (err, fsPath)->
callback = _.wrap callback, (cb, arg) ->
fs.unlink fsPath, (err) ->
if err?
logger.err project_id:project_id, fsPath:fsPath, "error deleting file"
cb(arg)
return callback(err) if err?
FileTypeManager.isBinary path, fsPath, (err, isFile)->
return callback(err) if err?
if isFile
self.p.processFile project_id, elementId, fsPath, path, source, callback #TODO clean up the stream written to disk here
self.p.processFile project_id, elementId, fsPath, path, source, callback
else
self.p.processDoc project_id, elementId, fsPath, path, source, callback

View file

@ -11,7 +11,8 @@ describe 'UpdateMerger :', ->
@updateReciver = {}
@projectLocator = {}
@projectEntityHandler = {}
@fs = {}
@fs =
unlink:sinon.stub().callsArgWith(1)
@FileTypeManager = {}
@updateMerger = SandboxedModule.require modulePath, requires:
'../Editor/EditorController': @editorController
@ -50,6 +51,7 @@ describe 'UpdateMerger :', ->
@updateMerger.mergeUpdate @project_id, filePath, @update, @source, =>
@FileTypeManager.isBinary.calledWith(filePath, @fsPath).should.equal true
@updateMerger.p.processDoc.calledWith(@project_id, doc_id, @fsPath, filePath, @source).should.equal true
@fs.unlink.calledWith(@fsPath).should.equal true
done()
it 'should process update as file when it is not a doc', (done)->
@ -62,6 +64,7 @@ describe 'UpdateMerger :', ->
@updateMerger.mergeUpdate @project_id, filePath, @update, @source, =>
@updateMerger.p.processFile.calledWith(@project_id, file_id, @fsPath, filePath, @source).should.equal true
@FileTypeManager.isBinary.calledWith(filePath, @fsPath).should.equal true
@fs.unlink.calledWith(@fsPath).should.equal true
done()