Permalink
Browse files

move refactorings - always deal with collections...

  • Loading branch information...
Davis W. Frank
Davis W. Frank committed May 17, 2012
1 parent b6b55ca commit a1adde7c62a01186473a51edf7afc0a12923d8be
@@ -45,11 +45,8 @@
}
function updateWith(filterName) {
- var tasks = taskList[filterName](currentItem);
- var list = new bulldog.TaskList(tasks);
-
router.updateNavigationView();
- router.updateTaskListView(list);
+ router.updateTaskListView(taskList[filterName](currentItem));
}
function projectsFrom(tasks) {
@@ -10,9 +10,9 @@
self.actionsForProject = function(projectName) {
if (projectName == 'All') {
- return this.models;
+ return self;
} else {
- return this.filter(byProjectName);
+ return filtered(byProjectName);
}
function byProjectName(task) {
@@ -21,15 +21,15 @@
};
self.actionsForContext = function(contextName) {
- return this.filter(byContextName);
+ return filtered(byContextName);
function byContextName(task) {
return task.get('context') == contextName;
}
};
self.nextActionsForContext = function(contextName) {
- return this.filter(forNextActionsByContextName);
+ return filtered(forNextActionsByContextName);
function forNextActionsByContextName(task) {
return task.get('context') == contextName && task.isNextAction();
@@ -44,5 +44,12 @@
}
return task.get('priority') || "ZZ";
}
+
+ function filtered(filterFn) {
+ var tasks = self.filter(filterFn);
+ return new namespace.TaskList(tasks);
+ }
+
+
};
}(jQuery, bulldog));
@@ -28,12 +28,10 @@ describe("bulldog.RouterAgent", function() {
expect(router.updateTaskListView).toHaveBeenCalled();
});
- it("should give the router all of the tasks, in priority order", function() {
+ it("should give the router all of the tasks", function() {
taskList = router.updateTaskListView.mostRecentCall.args[0];
expect(taskList.length).toEqual(5);
- expect(taskList.first().get('action')).toEqual('baz');
- expect(taskList.last().get('action')).toEqual('bar');
});
});
@@ -40,22 +40,22 @@ describe("bulldog.TaskList", function () {
describe("when the project is something", function() {
it("should return only the tasks for that project", function() {
expect(taskList.actionsForProject('Zip').length).toEqual(3);
- expect(taskList.actionsForProject('Zip')[0].get('action')).toEqual('corge');
+ expect(taskList.actionsForProject('Zip').first().get('action')).toEqual('quux');
});
});
});
describe("#actionsForContext", function() {
it("should return only tasks for the requested context", function() {
expect(taskList.actionsForContext('pc').length).toEqual(2);
- expect(taskList.actionsForContext('pc')[0].get('action')).toEqual('baz');
+ expect(taskList.actionsForContext('pc').first().get('action')).toEqual('baz');
});
});
describe("#nextActionsForContext", function() {
it("should return only tasks for the requested context", function() {
expect(taskList.nextActionsForContext('pc').length).toEqual(1);
- expect(taskList.nextActionsForContext('pc')[0].get('action')).toEqual('baz');
+ expect(taskList.nextActionsForContext('pc').first().get('action')).toEqual('baz');
});
});
});

0 comments on commit a1adde7

Please sign in to comment.