<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -781,10 +781,8 @@ class TodosController &lt; ApplicationController
       # check for next todo either from the due date or the show_from date
       date_to_check = todo.due.nil? ? todo.show_from : todo.due
       
-      # if both due and show_from are nil, check for a next todo with yesterday
-      # as reference point. We pick yesterday so that new todos for today will
-      # be created instead of new todos for tomorrow.
-      date_to_check = Time.zone.now-1.day if date_to_check.nil?
+      # if both due and show_from are nil, check for a next todo from now
+      date_to_check = Time.zone.now if date_to_check.nil?
       
       if recurring_todo.active? &amp;&amp; recurring_todo.has_next_todo(date_to_check)
         
@@ -792,7 +790,9 @@ class TodosController &lt; ApplicationController
         # the past. This is to make sure we do not get older todos for overdue
         # todos. I.e. checking a daily todo that is overdue with 5 days will
         # create a new todo which is overdue by 4 days if we don't shift the
-        # date. Discard the time part in the compare
+        # date. Discard the time part in the compare. We pick yesterday so that
+        # new todos due for today will be created instead of new todos for
+        # tomorrow.
         date = date_to_check.at_midnight &gt;= Time.zone.now.at_midnight ? date_to_check : Time.zone.now-1.day
         
         new_recurring_todo = create_todo_from_recurring_todo(recurring_todo, date) </diff>
      <filename>app/controllers/todos_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -406,6 +406,52 @@ class TodosControllerTest &lt; Test::Rails::TestCase
     # check that the todo is in the tickler
     assert !next_todo.show_from.nil?
   end
+
+  def test_toggle_check_on_rec_todo_show_from_today
+    login_as(:admin_user)
+    
+    # link todo_1 and recurring_todo_1
+    recurring_todo_1 = RecurringTodo.find(1)
+    todo_1 = Todo.find_by_recurring_todo_id(1)
+    today = Time.now.utc.at_midnight
+    
+    # change recurrence pattern to monthly and set show_from to today
+    recurring_todo_1.target = 'show_from_date'
+    recurring_todo_1.recurring_period = 'monthly'
+    recurring_todo_1.recurrence_selector = 0
+    recurring_todo_1.every_other1 = today.day
+    recurring_todo_1.every_other2 = 1
+    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.
+    xhr :post, :toggle_check, :id =&gt; todo_1.id, :_source_view =&gt; '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.find(:first, :conditions =&gt; {:recurring_todo_id =&gt; recurring_todo_1.id, :state =&gt; 'active'})
+    assert !new_todo.nil?
+
+    # mark new_todo as complete by toggle_check
+    xhr :post, :toggle_check, :id =&gt; new_todo.id, :_source_view =&gt; 'todo' 
+    new_todo.reload
+    assert todo_1.completed?
+    
+    # locate the new todo in tickler
+    new_todo = Todo.find(:first, :conditions =&gt; {:recurring_todo_id =&gt; recurring_todo_1.id, :state =&gt; 'deferred'})
+    assert !new_todo.nil?
+    
+    assert_equal &quot;Call Bill Gates every day&quot;, new_todo.description
+    # check that the new todo is not the same as todo_1
+    assert_not_equal todo_1.id, new_todo.id
+
+    # check that the new_todo is in the tickler to show next month
+    assert !new_todo.show_from.nil?
+    assert_equal Time.utc(today.year, today.month+1, today.day), new_todo.show_from
+  end
   
   def test_check_for_next_todo
     login_as :admin_user</diff>
      <filename>test/functional/todos_controller_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e31b05a6975e5ad8d78d1d478e238df7d837326a</id>
    </parent>
  </parents>
  <author>
    <name>Reinier Balt</name>
    <email>lrbalt@gmail.com</email>
  </author>
  <url>http://github.com/bsag/tracks/commit/f21908a2a0bf349dee694ba971b23a7d5f7e9984</url>
  <id>f21908a2a0bf349dee694ba971b23a7d5f7e9984</id>
  <committed-date>2008-10-29T08:40:45-07:00</committed-date>
  <authored-date>2008-10-29T08:40:45-07:00</authored-date>
  <message>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</message>
  <tree>bdcec3dbbb2323e366d47447bd151cc47a7a27e5</tree>
  <committer>
    <name>Reinier Balt</name>
    <email>lrbalt@gmail.com</email>
  </committer>
</commit>
