From d684f04d4f526cc4304a04833b55c652fcba704e Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 4 Apr 2014 16:40:53 +0100 Subject: [PATCH] moved moveEntity from collab manager to editor controller --- .../Features/Editor/EditorController.coffee | 6 +++++- .../managers/CollaberationManager.coffee | 6 ------ services/web/app/coffee/router.coffee | 2 +- .../Editor/EditorControllerTests.coffee | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/services/web/app/coffee/Features/Editor/EditorController.coffee b/services/web/app/coffee/Features/Editor/EditorController.coffee index ff5e512abc..c867942388 100644 --- a/services/web/app/coffee/Features/Editor/EditorController.coffee +++ b/services/web/app/coffee/Features/Editor/EditorController.coffee @@ -251,7 +251,11 @@ module.exports = EditorController = EditorRealTimeController.emitToRoom project_id, 'reciveEntityRename', entity_id, newName callback?() - + moveEntity: (project_id, entity_id, folder_id, entityType, callback)-> + Metrics.inc "editor.move-entity" + ProjectEntityHandler.moveEntity project_id, entity_id, folder_id, entityType, => + EditorRealTimeController.emitToRoom project_id, 'reciveEntityMove', entity_id, folder_id + callback?() p: notifyProjectUsersOfNewFolder: (project_id, folder_id, folder, callback = (error)->)-> diff --git a/services/web/app/coffee/managers/CollaberationManager.coffee b/services/web/app/coffee/managers/CollaberationManager.coffee index d6de7ca020..fdf72f5f4b 100644 --- a/services/web/app/coffee/managers/CollaberationManager.coffee +++ b/services/web/app/coffee/managers/CollaberationManager.coffee @@ -15,12 +15,6 @@ EditorRealTimeController = require('../Features/Editor/EditorRealTimeController' module.exports = class CollaberationManager constructor: (@io)-> - moveEntity: (project_id, entity_id, folder_id, entityType, callback)-> - metrics.inc "editor.move-entity" - projectEntityHandler.moveEntity project_id, entity_id, folder_id, entityType, => - EditorRealTimeController.emitToRoom project_id, 'reciveEntityMove', entity_id, folder_id - callback?() - renameProject: (project_id, window_id, newName, callback)-> newName = sanitize.escape(newName) projectHandler.renameProject project_id, window_id, newName, => diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 54adc4632d..ffba1033a5 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -295,7 +295,7 @@ module.exports = class Router client.on 'moveEntity', (entity_id, folder_id, entityType, callback)-> AuthorizationManager.ensureClientCanEditProject client, (error, project_id) => - collaberationManager.moveEntity(project_id, entity_id, folder_id, entityType, callback) + EditorController.moveEntity(project_id, entity_id, folder_id, entityType, callback) client.on 'setProjectName', (window_id, newName, callback)-> AuthorizationManager.ensureClientCanEditProject client, (error, project_id) => diff --git a/services/web/test/UnitTests/coffee/Editor/EditorControllerTests.coffee b/services/web/test/UnitTests/coffee/Editor/EditorControllerTests.coffee index 6c7204da08..23346f6379 100644 --- a/services/web/test/UnitTests/coffee/Editor/EditorControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Editor/EditorControllerTests.coffee @@ -643,3 +643,24 @@ describe "EditorController", -> @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'reciveEntityRename', @entity_id, @newName).should.equal true done() + + describe "moveEntity", -> + + beforeEach -> + @err = "errro" + @entity_id = "entity_id_here" + @entityType = "doc" + @folder_id = "313dasd21dasdsa" + @ProjectEntityHandler.moveEntity = sinon.stub().callsArgWith(4, @err) + @EditorRealTimeController.emitToRoom = sinon.stub() + + it "should call the ProjectEntityHandler", (done)-> + @EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, => + @ProjectEntityHandler.moveEntity.calledWith(@project_id, @entity_id, @folder_id, @entityType).should.equal true + done() + + + it "should emit the update to the room", (done)-> + @EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, => + @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'reciveEntityMove', @entity_id, @folder_id).should.equal true + done()