diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 0a3c1f19..d1c0dcf8 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -126,7 +126,7 @@ class TodoController < ApplicationController @item = check_user_return_item @original_item_context_id = @item.context_id @original_item_project_id = @item.project_id - + @original_item_was_deferred = @item.deferred? if params['item']['project_id'].blank? && !params['project_name'].blank? && params['project_name'] != 'None' project = @user.projects.find_by_name(params['project_name'].strip) unless project @@ -161,6 +161,7 @@ class TodoController < ApplicationController @saved = @item.update_attributes params["item"] @context_changed = @original_item_context_id != @item.context_id + @item_was_activated_from_deferred_state = @original_item_was_deferred && @item.active? if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todos.length; end @project_changed = @original_item_project_id != @item.project_id if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todos.length; end @@ -272,11 +273,12 @@ class TodoController < ApplicationController @down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'active', false]) end from.context do - @down_count = @user.contexts.find(@item.context_id).todos.count_in_state(:active) + @down_count = @user.contexts.find(@item.context_id).not_done_todo_count end from.project do unless @item.project_id == nil - @down_count = @user.projects.find(@item.project_id).todos.count_in_state(:active) + @down_count = @user.projects.find(@item.project_id).not_done_todo_count + @deferred_count = @user.projects.find(@item.project_id).deferred_todo_count end end from.deferred do @@ -291,11 +293,11 @@ class TodoController < ApplicationController @completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'completed', false]) end from.context do - @completed_count = @user.contexts.find(@item.context_id).todos.count_in_state(:completed) + @completed_count = @user.contexts.find(@item.context_id).done_todo_count end from.project do unless @item.project_id == nil - @completed_count = @user.projects.find(@item.project_id).todos.count_in_state(:completed) + @completed_count = @user.projects.find(@item.project_id).done_todo_count end end end diff --git a/tracks/app/views/todo/toggle_check.rjs b/tracks/app/views/todo/toggle_check.rjs index 1faff081..f02e3981 100644 --- a/tracks/app/views/todo/toggle_check.rjs +++ b/tracks/app/views/todo/toggle_check.rjs @@ -6,7 +6,7 @@ if @saved page.insert_html :top, "completed", :partial => 'todo/item', :locals => { :parent_container_type => "completed" } page.visual_effect :highlight, dom_id(@item, 'line'), {'startcolor' => "'#99ff99'"} page[empty_container_msg_div_id].show if @down_count == 0 && !empty_container_msg_div_id.nil? - page.show 'tickler-empty-nd' if source_view_is(:project) + page.show 'tickler-empty-nd' if source_view_is(:project) && @deferred_count == 0 page.hide 'empty-d' # If we've checked something as done, completed items can't be empty end if @remaining_undone_in_context == 0 && source_view_is(:todo) diff --git a/tracks/app/views/todo/update.rjs b/tracks/app/views/todo/update.rjs index 5ed32330..e906550c 100644 --- a/tracks/app/views/todo/update.rjs +++ b/tracks/app/views/todo/update.rjs @@ -43,6 +43,12 @@ if @saved page.insert_html :bottom, "tickler", :partial => 'todo/item', :locals => { :parent_container_type => parent_container_type } page['tickler-empty-nd'].hide page.replace_html "badge_count", @remaining_undone_in_project + elsif @item_was_activated_from_deferred_state + page[@item].remove + page['tickler-empty-nd'].show if (@deferred_count == 0) + page.insert_html :bottom, "p#{@item.project_id}", :partial => 'todo/item', :locals => { :parent_container_type => parent_container_type } + page["p#{@item.project_id}empty-nd"].hide + page.replace_html "badge_count", @remaining_undone_in_project else page.replace dom_id(@item), :partial => 'todo/item', :locals => { :parent_container_type => parent_container_type } page.visual_effect :highlight, dom_id(@item), :duration => 3 diff --git a/tracks/lib/todo_list.rb b/tracks/lib/todo_list.rb index e4dd6baf..5e3015c0 100644 --- a/tracks/lib/todo_list.rb +++ b/tracks/lib/todo_list.rb @@ -44,5 +44,9 @@ module Tracks self.todos.count_in_state(:completed) end + def deferred_todo_count + self.todos.count_in_state(:deferred) + end + end end diff --git a/tracks/test/fixtures/todos.yml b/tracks/test/fixtures/todos.yml index fa45c6da..cff6ed0b 100644 --- a/tracks/test/fixtures/todos.yml +++ b/tracks/test/fixtures/todos.yml @@ -186,3 +186,17 @@ end due: ~ completed_at: ~ user_id: 1 + +15: + id: 15 + context_id: 6 + project_id: 1 + description: Select Delorean model + notes: ~ + state: deferred + created_at: <%= today %> + due: ~ + completed_at: ~ + show_from: <%= next_week %> + user_id: 1 + diff --git a/tracks/test/functional/project_controller_test.rb b/tracks/test/functional/project_controller_test.rb index 2b95e178..e98ac5a0 100644 --- a/tracks/test/functional/project_controller_test.rb +++ b/tracks/test/functional/project_controller_test.rb @@ -22,14 +22,14 @@ class ProjectControllerTest < TodoContainerControllerTestBase p = projects(:timemachine) get :show, :url_friendly_name => p.url_friendly_name assert_not_nil assigns['deferred'] - assert_equal 0, assigns['deferred'].size + assert_equal 1, assigns['deferred'].size t = p.not_done_todos[0] t.show_from = 1.days.from_now.to_date t.save! get :show, :url_friendly_name => p.url_friendly_name - assert_equal 1, assigns['deferred'].size + assert_equal 2, assigns['deferred'].size end def test_create_project_via_ajax_increments_number_of_projects diff --git a/tracks/test/functional/todo_controller_test.rb b/tracks/test/functional/todo_controller_test.rb index f28a6668..55e9c7fb 100644 --- a/tracks/test/functional/todo_controller_test.rb +++ b/tracks/test/functional/todo_controller_test.rb @@ -49,6 +49,14 @@ class TodoControllerTest < Test::Unit::TestCase assert_equal 1, assigns['context_not_done_counts'][contexts(:lab).id] end + def test_deferred_count_for_project_source_view + @request.session['user_id'] = users(:admin_user).id + xhr :post, :toggle_check, :id => 5, :_source_view => 'project' + assert_equal 1, assigns['deferred_count'] + xhr :post, :toggle_check, :id => 15, :_source_view => 'project' + assert_equal 0, assigns['deferred_count'] + end + def test_destroy_item @request.session['user_id'] = users(:admin_user).id xhr :post, :destroy, :id => 1, :_source_view => 'todo' diff --git a/tracks/test/selenium/mark_todo_complete_1.rsel b/tracks/test/selenium/home/mark_todo_complete_1.rsel similarity index 68% rename from tracks/test/selenium/mark_todo_complete_1.rsel rename to tracks/test/selenium/home/mark_todo_complete_1.rsel index 052e2c43..ad3d1616 100644 --- a/tracks/test/selenium/mark_todo_complete_1.rsel +++ b/tracks/test/selenium/home/mark_todo_complete_1.rsel @@ -1,4 +1,4 @@ setup :fixtures => :all -include_partial 'login', :username => 'admin', :password => 'abracadabra' +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' click "xpath=//div[@id='c1'] //div[@id='todo_9'] //input[@class='item-checkbox']" wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_9']" diff --git a/tracks/test/selenium/mark_todo_complete_2.rsel b/tracks/test/selenium/home/mark_todo_complete_2.rsel similarity index 70% rename from tracks/test/selenium/mark_todo_complete_2.rsel rename to tracks/test/selenium/home/mark_todo_complete_2.rsel index 2388009d..1d5af6f4 100644 --- a/tracks/test/selenium/mark_todo_complete_2.rsel +++ b/tracks/test/selenium/home/mark_todo_complete_2.rsel @@ -1,5 +1,5 @@ setup :fixtures => :all -include_partial 'login', :username => 'admin', :password => 'abracadabra' +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' click "xpath=//div[@id='c5'] //div[@id='todo_5'] //input[@class='item-checkbox']" wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_5']" wait_for_not_visible 'c5' diff --git a/tracks/test/selenium/mark_todo_incomplete.rsel b/tracks/test/selenium/home/mark_todo_incomplete.rsel similarity index 71% rename from tracks/test/selenium/mark_todo_incomplete.rsel rename to tracks/test/selenium/home/mark_todo_incomplete.rsel index 2b76901d..64db1846 100644 --- a/tracks/test/selenium/mark_todo_incomplete.rsel +++ b/tracks/test/selenium/home/mark_todo_incomplete.rsel @@ -1,5 +1,5 @@ setup :fixtures => :all -include_partial 'login', :username => 'admin', :password => 'abracadabra' +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' click "xpath=//div[@id='completed'] //div[@id='todo_3'] //input[@class='item-checkbox']" wait_for_element_present "xpath=//div[@id='c4'] //div[@id='todo_3']" assert_not_visible "c4empty-nd" diff --git a/tracks/test/selenium/_login.rsel b/tracks/test/selenium/login/_login.rsel similarity index 100% rename from tracks/test/selenium/_login.rsel rename to tracks/test/selenium/login/_login.rsel diff --git a/tracks/test/selenium/login_failure.rsel b/tracks/test/selenium/login/login_failure.rsel similarity index 100% rename from tracks/test/selenium/login_failure.rsel rename to tracks/test/selenium/login/login_failure.rsel diff --git a/tracks/test/selenium/login_success.rsel b/tracks/test/selenium/login/login_success.rsel similarity index 100% rename from tracks/test/selenium/login_success.rsel rename to tracks/test/selenium/login/login_success.rsel diff --git a/tracks/test/selenium/mark_last_deferred_todo_complete_on_project_page.rsel b/tracks/test/selenium/mark_last_deferred_todo_complete_on_project_page.rsel deleted file mode 100644 index 4b836a1e..00000000 --- a/tracks/test/selenium/mark_last_deferred_todo_complete_on_project_page.rsel +++ /dev/null @@ -1,10 +0,0 @@ -setup :fixtures => :all -include_partial 'login', :username => 'admin', :password => 'abracadabra' -open "/project/Build_a_working_time_machine" -type "todo_description", "choose era" -type "todo_show_from", "1/1/2030" -click "//input[@value='Add item']" -wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container']" -open "/project/Build_a_working_time_machine" -click "xpath=//div[@id='tickler'] //input[@class='item-checkbox']" -wait_for_visible "tickler-empty-nd" diff --git a/tracks/test/selenium/create_deferred_todo_on_project_page.rsel b/tracks/test/selenium/project_detail/_add_deferred_todo.rsel similarity index 50% rename from tracks/test/selenium/create_deferred_todo_on_project_page.rsel rename to tracks/test/selenium/project_detail/_add_deferred_todo.rsel index 527b43cf..0dd17775 100644 --- a/tracks/test/selenium/create_deferred_todo_on_project_page.rsel +++ b/tracks/test/selenium/project_detail/_add_deferred_todo.rsel @@ -1,8 +1,4 @@ -setup :fixtures => :all -include_partial 'login', :username => 'admin', :password => 'abracadabra' -open "/project/Build_a_working_time_machine" -type "todo_description", "choose era" -type "todo_show_from", "1/1/2030" -click "//input[@value='Add item']" -wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container']" -assert_not_visible "tickler-empty-nd" \ No newline at end of file +type "todo_description", "choose era" +type "todo_show_from", "1/1/2030" +click "//input[@value='Add item']" +wait_for_element_present "xpath=//div[@id='tickler'] //div[@class='item-container']" diff --git a/tracks/test/selenium/project_detail/activate_deferred_todo.rsel b/tracks/test/selenium/project_detail/activate_deferred_todo.rsel new file mode 100644 index 00000000..59a8bea0 --- /dev/null +++ b/tracks/test/selenium/project_detail/activate_deferred_todo.rsel @@ -0,0 +1,11 @@ +setup :fixtures => :all +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' +open "/project/Build_a_working_time_machine" +include_partial 'project_detail/add_deferred_todo' +open "/project/Build_a_working_time_machine" +click "edit_icon_todo_15" +wait_for_element_present "show_from_todo_15" +type "show_from_todo_15", "" +click "//input[@value='Update']" +wait_for_element_present "xpath=//div[@id='p1'] //div[@id='todo_15']" +assert_not_visible "tickler-empty-nd" diff --git a/tracks/test/selenium/project_detail/activate_last_deferred_todo.rsel b/tracks/test/selenium/project_detail/activate_last_deferred_todo.rsel new file mode 100644 index 00000000..13a08d02 --- /dev/null +++ b/tracks/test/selenium/project_detail/activate_last_deferred_todo.rsel @@ -0,0 +1,10 @@ +setup :fixtures => :all +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' +open "/project/Build_a_working_time_machine" +open "/project/Build_a_working_time_machine" +click "edit_icon_todo_15" +wait_for_element_present "show_from_todo_15" +type "show_from_todo_15", "" +click "//input[@value='Update']" +wait_for_element_present "xpath=//div[@id='p1'] //div[@id='todo_15']" +wait_for_visible "tickler-empty-nd" diff --git a/tracks/test/selenium/project_detail/create_deferred_todo_on_project_page.rsel b/tracks/test/selenium/project_detail/create_deferred_todo_on_project_page.rsel new file mode 100644 index 00000000..602c9f3b --- /dev/null +++ b/tracks/test/selenium/project_detail/create_deferred_todo_on_project_page.rsel @@ -0,0 +1,5 @@ +setup :fixtures => :all +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' +open "/project/Build_a_working_time_machine" +include_partial 'project_detail/add_deferred_todo' +assert_not_visible "tickler-empty-nd" \ No newline at end of file diff --git a/tracks/test/selenium/defer_todo_on_project_page.rsel b/tracks/test/selenium/project_detail/defer_todo_on_project_page.rsel similarity index 78% rename from tracks/test/selenium/defer_todo_on_project_page.rsel rename to tracks/test/selenium/project_detail/defer_todo_on_project_page.rsel index 040a63ac..1e90cf55 100644 --- a/tracks/test/selenium/defer_todo_on_project_page.rsel +++ b/tracks/test/selenium/project_detail/defer_todo_on_project_page.rsel @@ -1,5 +1,5 @@ setup :fixtures => :all -include_partial 'login', :username => 'admin', :password => 'abracadabra' +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' open "/project/Build_a_working_time_machine" click "edit_icon_todo_5" wait_for_element_present "show_from_todo_5" diff --git a/tracks/test/selenium/project_detail/mark_deferred_todo_complete.rsel b/tracks/test/selenium/project_detail/mark_deferred_todo_complete.rsel new file mode 100644 index 00000000..278526bb --- /dev/null +++ b/tracks/test/selenium/project_detail/mark_deferred_todo_complete.rsel @@ -0,0 +1,7 @@ +setup :fixtures => :all +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' +open "/project/Build_a_working_time_machine" +include_partial 'project_detail/add_deferred_todo' +click "xpath=//div[@id='tickler'] //div[@id='todo_15'] //input[@class='item-checkbox']" +wait_for_element_present "xpath=//div[@id='completed'] //div[@id='todo_15']" +assert_not_visible "tickler-empty-nd" \ No newline at end of file diff --git a/tracks/test/selenium/project_detail/mark_last_deferred_todo_complete_on_project_page.rsel b/tracks/test/selenium/project_detail/mark_last_deferred_todo_complete_on_project_page.rsel new file mode 100644 index 00000000..a072f32c --- /dev/null +++ b/tracks/test/selenium/project_detail/mark_last_deferred_todo_complete_on_project_page.rsel @@ -0,0 +1,5 @@ +setup :fixtures => :all +include_partial 'login/login', :username => 'admin', :password => 'abracadabra' +open "/project/Build_a_working_time_machine" +click "xpath=//div[@id='tickler'] //div[@id='todo_15'] //input[@class='item-checkbox']" +wait_for_visible "tickler-empty-nd" diff --git a/tracks/test/unit/project_test.rb b/tracks/test/unit/project_test.rb index 4a9dc77c..7ebac68f 100644 --- a/tracks/test/unit/project_test.rb +++ b/tracks/test/unit/project_test.rb @@ -75,12 +75,12 @@ class ProjectTest < Test::Unit::TestCase end def test_delete_project_deletes_todos_within_it - assert_equal 2, @timemachine.todos.count - timemachine_todo_1_id = @timemachine.todos[0].id - timemachine_todo_2_id = @timemachine.todos[1].id + assert_equal 3, @timemachine.todos.count + timemachine_todo_ids = @timemachine.todos.map{ |t| t.id } @timemachine.destroy - assert !Todo.exists?(timemachine_todo_1_id) - assert !Todo.exists?(timemachine_todo_2_id) + timemachine_todo_ids.each do |t_id| + assert !Todo.exists?(t_id) + end end def test_not_done_todos @@ -100,11 +100,11 @@ class ProjectTest < Test::Unit::TestCase end def test_deferred_todos - assert_equal 0, @timemachine.deferred_todos.size + assert_equal 1, @timemachine.deferred_todos.size t = @timemachine.not_done_todos[0] t.show_from = 1.days.from_now.to_date t.save! - assert_equal 1, Project.find(@timemachine.id).deferred_todos.size + assert_equal 2, Project.find(@timemachine.id).deferred_todos.size end def test_url_friendly_name_for_name_with_spaces