public
Description: Tracks is a GTD(TM) web application, built with Ruby on Rails
Homepage: http://www.rousette.org.uk/projects/
Clone URL: git://github.com/bsag/tracks.git
Click here to lend your support to: tracks and make a donation at www.pledgie.com !
Fixes corner case where checking a monthly recurring todo complete on
the same day the todo comes from tickler, a new todo is created and not
put in the tickler for next month, but for today
lrbalt (author)
Wed Oct 29 08:40:45 -0700 2008
commit  f21908a2a0bf349dee694ba971b23a7d5f7e9984
tree    bdcec3dbbb2323e366d47447bd151cc47a7a27e5
parent  e31b05a6975e5ad8d78d1d478e238df7d837326a
...
781
782
783
784
785
786
787
 
 
788
789
790
...
792
793
794
795
 
 
 
796
797
798
...
781
782
783
 
 
 
 
784
785
786
787
788
...
790
791
792
 
793
794
795
796
797
798
0
@@ -781,10 +781,8 @@ class TodosController < ApplicationController
0
       # check for next todo either from the due date or the show_from date
0
       date_to_check = todo.due.nil? ? todo.show_from : todo.due
0
       
0
-      # if both due and show_from are nil, check for a next todo with yesterday
0
-      # as reference point. We pick yesterday so that new todos for today will
0
-      # be created instead of new todos for tomorrow.
0
-      date_to_check = Time.zone.now-1.day if date_to_check.nil?
0
+      # if both due and show_from are nil, check for a next todo from now
0
+      date_to_check = Time.zone.now if date_to_check.nil?
0
       
0
       if recurring_todo.active? && recurring_todo.has_next_todo(date_to_check)
0
         
0
@@ -792,7 +790,9 @@ class TodosController < ApplicationController
0
         # the past. This is to make sure we do not get older todos for overdue
0
         # todos. I.e. checking a daily todo that is overdue with 5 days will
0
         # create a new todo which is overdue by 4 days if we don't shift the
0
-        # date. Discard the time part in the compare
0
+        # date. Discard the time part in the compare. We pick yesterday so that
0
+        # new todos due for today will be created instead of new todos for
0
+        # tomorrow.
0
         date = date_to_check.at_midnight >= Time.zone.now.at_midnight ? date_to_check : Time.zone.now-1.day
0
         
0
         new_recurring_todo = create_todo_from_recurring_todo(recurring_todo, date) 
...
406
407
408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
410
411
...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
0
@@ -406,6 +406,52 @@ class TodosControllerTest < Test::Rails::TestCase
0
     # check that the todo is in the tickler
0
     assert !next_todo.show_from.nil?
0
   end
0
+
0
+  def test_toggle_check_on_rec_todo_show_from_today
0
+    login_as(:admin_user)
0
+    
0
+    # link todo_1 and recurring_todo_1
0
+    recurring_todo_1 = RecurringTodo.find(1)
0
+    todo_1 = Todo.find_by_recurring_todo_id(1)
0
+    today = Time.now.utc.at_midnight
0
+    
0
+    # change recurrence pattern to monthly and set show_from to today
0
+    recurring_todo_1.target = 'show_from_date'
0
+    recurring_todo_1.recurring_period = 'monthly'
0
+    recurring_todo_1.recurrence_selector = 0
0
+    recurring_todo_1.every_other1 = today.day
0
+    recurring_todo_1.every_other2 = 1
0
+    recurring_todo_1.save
0
+    
0
+    # mark todo_1 as complete by toggle_check, this gets rid of todo_1 that was
0
+    # not correctly created from the adjusted recurring pattern we defined
0
+    # above.
0
+    xhr :post, :toggle_check, :id => todo_1.id, :_source_view => 'todo' 
0
+    todo_1.reload
0
+    assert todo_1.completed?
0
+
0
+    # locate the new todo. This todo is created from the adjusted recurring
0
+    # pattern defined in this test
0
+    new_todo = Todo.find(:first, :conditions => {:recurring_todo_id => recurring_todo_1.id, :state => 'active'})
0
+    assert !new_todo.nil?
0
+
0
+    # mark new_todo as complete by toggle_check
0
+    xhr :post, :toggle_check, :id => new_todo.id, :_source_view => 'todo' 
0
+    new_todo.reload
0
+    assert todo_1.completed?
0
+    
0
+    # locate the new todo in tickler
0
+    new_todo = Todo.find(:first, :conditions => {:recurring_todo_id => recurring_todo_1.id, :state => 'deferred'})
0
+    assert !new_todo.nil?
0
+    
0
+    assert_equal "Call Bill Gates every day", new_todo.description
0
+    # check that the new todo is not the same as todo_1
0
+    assert_not_equal todo_1.id, new_todo.id
0
+
0
+    # check that the new_todo is in the tickler to show next month
0
+    assert !new_todo.show_from.nil?
0
+    assert_equal Time.utc(today.year, today.month+1, today.day), new_todo.show_from
0
+  end
0
   
0
   def test_check_for_next_todo
0
     login_as :admin_user

Comments