From a6c32889ceb2dab62d44faf885c1f7ec0e2cc01f Mon Sep 17 00:00:00 2001 From: Ian Young Date: Sat, 14 Sep 2013 00:09:00 -0700 Subject: [PATCH 1/2] Bug repeating monthly recurring todos --- app/models/recurring_todo.rb | 2 +- test/controllers/todos_controller_test.rb | 38 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/models/recurring_todo.rb b/app/models/recurring_todo.rb index 3769e585..dc79fc5f 100644 --- a/app/models/recurring_todo.rb +++ b/app/models/recurring_todo.rb @@ -489,7 +489,7 @@ class RecurringTodo < ActiveRecord::Base case self.recurrence_selector when 0 # specific day of the month - if start.mday > day + if start.mday >= day # there is no next day n in this month, search in next month # # start += n.months diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index 3e6b3e0c..e51773d6 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -799,6 +799,44 @@ class TodosControllerTest < ActionController::TestCase assert next_todo.due > todo.due end + def test_check_for_next_todo_monthly + login_as :admin_user + + tomorrow = Time.zone.now + 1.day + + # Given a monthly repeat pattern + recurring_todo = RecurringTodo.find(5) + recurring_todo.target = "due_date" + recurring_todo.recurring_period = "monthly" + recurring_todo.every_other1 = tomorrow.day + recurring_todo.every_other2 = 1 + recurring_todo.save + + # Given a recurring todo (todo) that belongs to the repeat pattern (recurring_todo) and is due tomorrow + todo = Todo.where(:recurring_todo_id => 1).first + assert todo.from_recurring_todo? + todo.recurring_todo_id = 5 # rewire todo to the repeat pattern above + todo.due = tomorrow + todo.save! + + # When I mark the todo complete + xhr :post, :toggle_check, :id => todo.id, :_source_view => 'todo' + todo.reload + assert todo.completed? + + # Then there should not be an active todo beloning to the repeat pattern + next_todo = Todo.where(:recurring_todo_id => recurring_todo.id, :state => 'active').first + assert next_todo.nil? + + # Then there should be one new deferred todo + next_todo = Todo.where(:recurring_todo_id => recurring_todo.id, :state => 'deferred').first + assert !next_todo.nil? + assert !next_todo.show_from.nil? + + # check that the due date of the new todo is later than tomorrow + assert next_todo.due > todo.due + end + ############ # todo notes ############ From 4cd8688d9a90e4cb662a4e0fe61df82f5c6208ef Mon Sep 17 00:00:00 2001 From: Ian Young Date: Sat, 14 Sep 2013 22:11:23 -0700 Subject: [PATCH 2/2] Fix failing test As far as I can tell, this is how the test is intended to work, and how it works in v2.2.2. If a recurring todo set to show on the date is completed *on* the specified date, it will create a deferred one for the *next* month. --- test/controllers/todos_controller_test.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index e51773d6..6a4d5ca6 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -729,23 +729,11 @@ class TodosControllerTest < ActionController::TestCase recurring_todo_1.every_other2 = 1 assert recurring_todo_1.save - # mark todo_1 as complete by toggle_check, this gets rid of todo_1 that was - # not correctly created from the adjusted recurring pattern we defined - # above. + # mark todo_1 as complete by toggle_check xhr :post, :toggle_check, :id => todo_1.id, :_source_view => 'todo' todo_1.reload assert todo_1.completed? - # locate the new todo. This todo is created from the adjusted recurring - # pattern defined in this test - new_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'active').first - assert !new_todo.nil? - - # mark new_todo as complete by toggle_check - xhr :post, :toggle_check, :id => new_todo.id, :_source_view => 'todo' - new_todo.reload - assert todo_1.completed? - # locate the new todo in tickler new_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'deferred').first assert !new_todo.nil?