From b387b27f4a6f5009a2ad8c5d374261447686fc5a Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Thu, 20 Oct 2011 12:10:24 -0500 Subject: [PATCH] Show deferred actions on the project listing and sidebar If a project does not have any active actions, then it will now display that it has x number of deferred actions. Fixes #1084 --- app/controllers/application_controller.rb | 19 ++++++- features/project_list.feature | 8 +-- .../step_definitions/project_list_steps.rb | 49 +++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d18ebbda..6f75ea61 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -91,8 +91,15 @@ class ApplicationController < ActionController::Base # def count_undone_todos_phrase(todos_parent, string="actions") count = count_undone_todos(todos_parent) - word = count == 1 ? string.singularize : string.pluralize - return count.to_s + " " + word + deferred_count = count_deferred_todos(todos_parent) + if count == 0 && deferred_count > 0 + word = deferred_count == 1 ? string.singularize : string.pluralize + word = "deferred " + word + deferred_count.to_s + " " + word + else + word = count == 1 ? string.singularize : string.pluralize + count.to_s + " " + word + end end def count_undone_todos(todos_parent) @@ -106,6 +113,14 @@ class ApplicationController < ActionController::Base count || 0 end + def count_deferred_todos(todos_parent) + if todos_parent.nil? + count = 0 + else + count = todos_parent.todos.deferred.count + end + end + # Convert a date object to the format specified in the user's preferences in # config/settings.yml # diff --git a/features/project_list.feature b/features/project_list.feature index bccb8f07..a57ba857 100644 --- a/features/project_list.feature +++ b/features/project_list.feature @@ -116,25 +116,25 @@ Feature: Manage the list of projects And the badge should show 4 And the project list badge for "active" projects should show 4 - @selenium @wip + @selenium Scenario: Listing projects with only active actions Given I have a project "do it now" with 2 active todos When I go to the projects page Then the project "do it now" should have 2 actions listed - @selenium @wip + @selenium Scenario: Listing projects with both active and deferred actions Given I have a project "now and later" with 2 active actions and 2 deferred actions When I go to the projects page Then the project "now and later" should have 2 actions listed - @selenium @wip + @selenium Scenario: Listing projects with only deferred actions Given I have a project "only later" with 3 deferred actions When I go to the projects page Then the project "only later" should have 3 deferred actions listed - @selenium @wip + @selenium Scenario: Listing projects with no actions Given I have a project "all done" with 0 active actions and 0 deferred actions When I go to the projects page diff --git a/features/step_definitions/project_list_steps.rb b/features/step_definitions/project_list_steps.rb index 3142e147..270a5f78 100644 --- a/features/step_definitions/project_list_steps.rb +++ b/features/step_definitions/project_list_steps.rb @@ -90,3 +90,52 @@ end Then /^the new project form should not be visible$/ do selenium.is_visible("project_new").should == false end + + +Given /^I have a project "([^"]*)" with (\d+) active todos$/ do |name, count| + @context = @current_user.contexts.find_or_create_by_name("Context A") + @project = @current_user.projects.find_or_create_by_name(name) + + @todos=[] + 1.upto count.to_i do |i| + todo = @current_user.todos.create!( + :project_id => @project.id, + :context_id => @context.id, + :description => "todo #{i}") + @todos << todo + end +end + +Then /^the project "([^"]*)" should have (\d+) actions listed$/ do |name, count| + project = @current_user.projects.find_by_name(name) + project.should_not be_nil + xpath = "//div[@id='list-active-projects-container']//div[@id='project_#{project.id}']//span[@class='needsreview']" + selenium.get_text("xpath=#{xpath}").should == "#{project.name} (#{count} actions)" +end + +Given /^I have a project "([^"]*)" with (\d+) active actions and (\d+) deferred actions$/ do |name, active_count, deferred_count| + Given "I have a project \"#{name}\" with #{active_count} active todos" + Given "I have a project \"#{name}\" with #{deferred_count} deferred actions" +end + +Given /^I have a project "([^"]*)" with (\d+) deferred actions$/ do |name, deferred| + @context = @current_user.contexts.find_or_create_by_name("Context A") + @project = @current_user.projects.find_or_create_by_name(name) + + 1.upto deferred.to_i do |i| + todo = @current_user.todos.create!( + :project_id => @project.id, + :context_id => @context.id, + :description => "deferred todo #{i}") + todo.show_from = Time.zone.now + 1.week + todo.save! + end +end + +Then /^the project "([^"]*)" should have (\d+) deferred actions listed$/ do |name, deferred| + project = @current_user.projects.find_by_name(name) + project.should_not be_nil + xpath = "//div[@id='list-active-projects-container']//div[@id='project_#{project.id}']//span[@class='needsreview']" + selenium.get_text("xpath=#{xpath}").should == "#{project.name} (#{deferred} deferred actions)" +end +