Created
November 3, 2011 02:23
-
-
Save searls/1335607 to your computer and use it in GitHub Desktop.
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('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']); | |
}); | |
}); | |
}); | |
}); |
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
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