Created
June 4, 2012 14:14
-
-
Save pivotal-medici/2868652 to your computer and use it in GitHub Desktop.
Ember run loop sync issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MR.TopicsLinkView = Em.View.extend({ | |
topic: null, | |
tagName: 'li', | |
classNames: 'topic link', | |
templateName: 'ember/templates/topics/link', | |
contextBinding: 'topic', | |
didInsertElement: function() { | |
this._bindDrag(); | |
this._bindDrop(); | |
}, | |
_bindDrag: function() { | |
var $view = this.$(); | |
$view.draggable({ | |
helper: function() { | |
return $view.emberClone(); | |
}, | |
scope: 'reorder-topics' | |
}); | |
$view.bind('dragstart', $.callbackArgs(this._onDragStart, this)); | |
}, | |
_bindDrop: function() { | |
var $view = this.$(); | |
$view.droppable({ | |
scope: 'reorder-topics', | |
greedy: true, | |
activeClass: 'drag-active', | |
hoverClass: 'drag-hover' | |
}); | |
$view.bind('drop', $.callbackArgs(this._onDrop, this)); | |
}, | |
_onDragStart: function(event, ui, view) { | |
var controller, topic; | |
controller = view.get('controller'); | |
topic = view.get('topic'); | |
controller.setDraggingTopic(topic); | |
}, | |
_onDrop: function(event, ui, view) { | |
var controller, topicBefore; | |
controller = view.get('controller'); | |
topicBefore = view.get('topic'); | |
controller.saveDraggingAfter(topicBefore); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("MR.TopicsLinkView", function() { | |
var ui, controller, view, topic; | |
beforeEach(function() { | |
ui = {}; | |
controller = MR.TopicsController.create(); | |
topic = MR.Topic.createRecord(); | |
Em.run(function() { | |
view = MR.TopicsLinkView.create({ | |
controller: controller, | |
topic: topic | |
}); | |
view.appendTo('#jasmine_content'); | |
}); | |
}); | |
afterEach(function() { | |
view.destroy(); | |
}); | |
describe("drag n drop", function() { | |
describe("drag", function() { | |
it("sets the dragging topic to itself", function() { | |
spyOn(controller, 'setDraggingTopic'); | |
view.$().trigger('dragstart', ui); | |
expect(controller.setDraggingTopic).emberToHaveBeenCalledWith(topic); | |
}); | |
}); | |
describe("drop", function() { | |
it("saves the dropped topic", function() { | |
spyOn(controller, 'saveDraggingAfter'); | |
view.$().trigger('drop', ui); | |
expect(controller.saveDraggingAfter).emberToHaveBeenCalledWith(topic); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment