Skip to content

Instantly share code, notes, and snippets.

@searls
Created November 3, 2011 02:23
Show Gist options
  • Save searls/1335607 to your computer and use it in GitHub Desktop.
Save searls/1335607 to your computer and use it in GitHub Desktop.
describe('CallList', function() {
var subject;
beforeEach(function() {
subject = new CallList({items: ['A','B','C']});
});
describe("#moveUp", function() {
context("moving up C", function() {
beforeEach(function() {
subject.moveUp('C');
});
it("places it above B", function() {
expect(subject.get('items')).toEqual(['A','C','B']);
});
});
context("moving up B", function() {
beforeEach(function() {
subject.moveUp('B');
});
it("places B above A", function() {
expect(subject.get('items')).toEqual(['B','A','C']);
});
});
context("moving up A", function() {
beforeEach(function() {
subject.moveUp('A');
});
it("leaves the items as they were", function() {
expect(subject.get('items')).toEqual(['A','B','C']);
});
});
});
});
window.CallList = Backbone.Model.extend({
moveUp: function(item) {
var items = this.get('items');
var index = _(items).indexOf(item) - 1;
if(index >= 0) {
items.splice(index,2,item,items[index]);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment