Permalink
Browse files

Allow Story.column to be overridden.

Allows overriding default calculated column, required when unstarted
stories are pulled into the in progress column when the velocity allows.

Fixes bug when dropping unstarted stories into the empty backlog fails
when the project has no started or done stories but has at least one
unstarted story in the in progress column.
  • Loading branch information...
1 parent 6dff031 commit 41d15b4e800890eb9f3839df504e136ec50178c6 @malclocke malclocke committed Jan 11, 2012
@@ -28,7 +28,7 @@ var StoryCollection = Backbone.Collection.extend({
// #backlog or #chilly_bin
column: function(column) {
return this.select(function(story) {
- return story.column() == column;
+ return story.column == column;
});
},
@@ -249,6 +249,12 @@ var Project = Backbone.Model.extend({
// few stories from the backlog, unless the points total of the stories
// in progress already equal or exceed the project velocity
if (currentIteration.canTakeStory(story)) {
+
+ // On initialisation, a stories column is determined based on the
+ // story state. For unstarted stories this defaults to #backlog.
+ // Stories matched here need this value overridden to #in_progress
+ story.column = '#in_progress';
+
currentIteration.get('stories').push(story);
return;
}
@@ -9,6 +9,7 @@ var Story = Backbone.Model.extend({
this.maybeUnwrap(args);
this.initNotes();
+ this.setColumn();
},
@@ -18,6 +19,7 @@ var Story = Backbone.Model.extend({
}
model.setAcceptedAt();
+ model.setColumn();
},
moveBetween: function(before, after) {
@@ -67,7 +69,7 @@ var Story = Backbone.Model.extend({
story_type: "feature"
},
- column: function() {
+ setColumn: function() {
var column = '#in_progress';
@@ -89,7 +91,7 @@ var Story = Backbone.Model.extend({
break;
}
- return column;
+ this.column = column;
},
clear: function() {
@@ -20,7 +20,7 @@ var ProjectView = Backbone.View.extend({
// second argument, so also check that column is a string and not an
// object for those cases.
if (typeof column === 'undefined' || typeof column !== 'string') {
- column = story.column();
+ column = story.column;
}
var view = new StoryView({model: story});
$(column).append(view.render().el);
@@ -94,14 +94,14 @@ describe('StoryCollection collection', function() {
it("should return all stories in the done column", function() {
expect(this.stories.column('#done')).toEqual([]);
- this.story1.column = function() {return '#done';};
+ this.story1.column = '#done';
expect(this.stories.column('#done')).toEqual([this.story1]);
});
it("returns a set of columns", function() {
- this.story1.column = function() {return '#done';};
- this.story2.column = function() {return '#current';};
- this.story3.column = function() {return '#backlog';};
+ this.story1.column = '#done';
+ this.story2.column = '#current';
+ this.story3.column = '#backlog';
expect(this.stories.columns(['#backlog', '#current', '#done']))
.toEqual([this.story3,this.story2,this.story1]);
});
@@ -5,7 +5,9 @@ describe('Story model', function() {
name: 'project',
defaults: {point_values: [0, 1, 2, 3]},
users: { get: function() {} },
- current_user: { id: 999 }
+ current_user: { id: 999 },
+ currentIterationNumber: function() { return 1; },
+ getIterationNumberForDate: function() { return 999; }
});
var collection = {
project: new Project(), url: '/foo', remove: function() {},
@@ -146,25 +148,26 @@ describe('Story model', function() {
describe('column', function() {
it('should return the right column', function() {
this.story.set({state: 'unscheduled'});
- expect(this.story.column()).toEqual('#chilly_bin');
+ expect(this.story.column).toEqual('#chilly_bin');
this.story.set({state: 'unstarted'});
- expect(this.story.column()).toEqual('#backlog');
+ expect(this.story.column).toEqual('#backlog');
this.story.set({state: 'started'});
- expect(this.story.column()).toEqual('#in_progress');
+ expect(this.story.column).toEqual('#in_progress');
this.story.set({state: 'delivered'});
- expect(this.story.column()).toEqual('#in_progress');
+ expect(this.story.column).toEqual('#in_progress');
this.story.set({state: 'rejected'});
- expect(this.story.column()).toEqual('#in_progress');
+ expect(this.story.column).toEqual('#in_progress');
// If the story is accepted, but it's accepted_at date is within the
// current iteration, it should be in the in_progress column, otherwise
// it should be in the #done column
sinon.stub(this.story, 'iterationNumber').returns(1);
this.story.collection.project.currentIterationNumber = sinon.stub().returns(2);
this.story.set({state: 'accepted'});
- expect(this.story.column()).toEqual('#done');
+ expect(this.story.column).toEqual('#done');
this.story.collection.project.currentIterationNumber.returns(1);
- expect(this.story.column()).toEqual('#in_progress');
+ this.story.setColumn();
+ expect(this.story.column).toEqual('#in_progress');
});
});

0 comments on commit 41d15b4

Please sign in to comment.