Skip to content

Commit

Permalink
Ensure done iterations are sorted numerically.
Browse files Browse the repository at this point in the history
Chrome sorts object keys numerically by default, so this hadn't
been showing up in my dev environment.

This guarantees the done iterations will be in the
correct numeric order when rebuilding the project iterations.

Fixes fulcrum-agile#57
  • Loading branch information
Malcolm Locke committed Oct 18, 2011
1 parent 7a8f91e commit 2c5de84
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion public/javascripts/models/iteration.js
Expand Up @@ -113,7 +113,7 @@ var Iteration = Backbone.Model.extend({
var end = parseInt(endIteration.get('number'), 10);

if (end < start) {
throw "end iteration number must be greater than start iteration number";
throw "end iteration number:" + end + " must be greater than start iteration number:" + start ;
}

var missing_range = _.range(start, end);
Expand Down
9 changes: 7 additions & 2 deletions public/javascripts/models/project.js
Expand Up @@ -202,13 +202,18 @@ var Project = Backbone.Model.extend({
// Clear the project iterations
this.iterations = [];

var done_iterations = _.groupBy(this.stories.column('#done'),
var doneIterations = _.groupBy(this.stories.column('#done'),
function(story) {
return story.iterationNumber();
});

_.each(done_iterations, function(stories, iterationNumber) {
// groupBy() returns an object with keys of the iteration number
// and values of the stories array. Ensure the keys are sorted
// in numeric order.
var doneNumbers = _.keys(doneIterations).sort();

_.each(doneNumbers, function(iterationNumber) {
var stories = doneIterations[iterationNumber];
var iteration = new Iteration({
'number': iterationNumber, 'stories': stories, column: '#done'
});
Expand Down
2 changes: 1 addition & 1 deletion spec/javascripts/models/iteration.spec.js
Expand Up @@ -189,7 +189,7 @@ describe("iteration", function() {
var that = this;
expect(function() {
Iteration.createMissingIterations('#done', that.start, end);
}).toThrow("end iteration number must be greater than start iteration number");
}).toThrow("end iteration number:1 must be greater than start iteration number:2");
});

it("should return an empty array when start is undefined and end is number 1", function() {
Expand Down

0 comments on commit 2c5de84

Please sign in to comment.