<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -3,7 +3,7 @@ module AuthenticatedTestHelper
   def login_as(user)
     @request.session['user_id'] = user ? users(user).id : nil
   end
-  
+
   def content_type(type)
     @request.env['Content-Type'] = type
   end</diff>
      <filename>lib/authenticated_test_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,107 @@ class RecurringTodosControllerTest &lt; ActionController::TestCase
     login_as(:admin_user)
     xhr :post, :destroy, :id =&gt; 1, :_source_view =&gt; 'todo'
     assert_rjs :page, &quot;recurring_todo_1&quot;, :remove
+    begin 
+      rc = RecurringTodo.find(1)
+    rescue
+      rc = nil      
+    end
+    assert_nil rc
   end
+  
+  def test_new_recurring_todo
+    login_as(:admin_user)
+    orig_rt_count = RecurringTodo.count
+    orig_todo_count = Todo.count
+    put :create,       
+      &quot;context_name&quot;=&gt;&quot;library&quot;, 
+      &quot;project_name&quot;=&gt;&quot;Build a working time machine&quot;, 
+      &quot;recurring_todo&quot; =&gt; 
+      {
+      &quot;daily_every_x_days&quot;=&gt;&quot;1&quot;, 
+      &quot;daily_selector&quot;=&gt;&quot;daily_every_x_day&quot;, 
+      &quot;description&quot;=&gt;&quot;new recurring pattern&quot;, 
+      &quot;end_date&quot; =&gt; &quot;31/08/2010&quot;,
+      &quot;ends_on&quot; =&gt; &quot;ends_on_end_date&quot;,
+      &quot;monthly_day_of_week&quot; =&gt; &quot;1&quot;,
+      &quot;monthly_every_x_day&quot; =&gt; &quot;18&quot;,
+      &quot;monthly_every_x_month2&quot; =&gt; &quot;1&quot;,
+      &quot;monthly_every_x_month&quot; =&gt; &quot;1&quot;,
+      &quot;monthly_every_xth_day&quot;=&gt;&quot;1&quot;,
+      &quot;monthly_selector&quot;=&gt;&quot;monthly_every_x_day&quot;,
+      &quot;notes&quot;=&gt;&quot;with some notes&quot;,
+      &quot;number_of_occurences&quot; =&gt; &quot;&quot;,
+      &quot;recurring_period&quot;=&gt;&quot;yearly&quot;,
+      &quot;recurring_show_days_before&quot;=&gt;&quot;10&quot;,
+      &quot;recurring_target&quot;=&gt;&quot;due_date&quot;,
+      &quot;start_from&quot;=&gt;&quot;18/08/2008&quot;,
+      &quot;weekly_every_x_week&quot;=&gt;&quot;1&quot;,
+      &quot;weekly_return_monday&quot;=&gt;&quot;m&quot;,
+      &quot;yearly_day_of_week&quot;=&gt;&quot;1&quot;,
+      &quot;yearly_every_x_day&quot;=&gt;&quot;8&quot;,
+      &quot;yearly_every_xth_day&quot;=&gt;&quot;1&quot;,
+      &quot;yearly_month_of_year2&quot;=&gt;&quot;8&quot;,
+      &quot;yearly_month_of_year&quot;=&gt;&quot;6&quot;,
+      &quot;yearly_selector&quot;=&gt;&quot;yearly_every_x_day&quot;
+    }, 
+      &quot;tag_list&quot;=&gt;&quot;one, two, three, four&quot;
+    
+    # check new recurring todo added
+    assert_equal orig_rt_count+1, RecurringTodo.count  
+    # check new todo added
+    assert_equal orig_todo_count+1, Todo.count
+  end
+  
+  def test_recurring_todo_toggle_check
+    # the test fixtures did add recurring_todos but not the corresponding todos,
+    # so we check complete and uncheck to force creation of a todo from the
+    # pattern
+    login_as(:admin_user)
 
+    # mark as complete
+    xhr :post, :toggle_check, :id=&gt;1, :_source_view=&gt;&quot;&quot;
+    recurring_todo_1 = RecurringTodo.find(1)
+    assert recurring_todo_1.completed?
+    
+    todo_count = Todo.count
+    
+    # mark as active
+    xhr :post, :toggle_check, :id=&gt;1, :_source_view=&gt;&quot;&quot;    
+    recurring_todo_1.reload
+    assert recurring_todo_1.active?
+    
+    # by making  active, a new todo should be created from the pattern
+    assert_equal todo_count+1, Todo.count
+    
+    # find the new todo and check its description
+    new_todo = Todo.find_by_recurring_todo_id 1
+    assert_equal &quot;Call Bill Gates every day&quot;, new_todo.description
+  end
+
+  def test_creating_recurring_todo_with_show_from_in_past
+    login_as(:admin_user)
+    
+    @yearly = RecurringTodo.find(5) # yearly on june 8th
+    
+    # change due date in four days from now and show from 10 days before, i.e. 6
+    # days ago
+    target_date = Time.now.utc + 4.days
+    @yearly.every_other1 = target_date.day
+    @yearly.every_other2 = target_date.month
+    @yearly.show_from_delta = 10
+    assert @yearly.save
+    
+    # toggle twice to force generation of new todo
+    xhr :post, :toggle_check, :id=&gt;5, :_source_view=&gt;&quot;&quot;
+    xhr :post, :toggle_check, :id=&gt;5, :_source_view=&gt;&quot;&quot;
+
+    new_todo = Todo.find_by_recurring_todo_id 5
+    
+    # due date should be the target_date
+    assert_equal Time.utc(target_date.year, target_date.month, target_date.day), new_todo.due
+    
+    # show_from should be nil since now+4.days-10.days is in the past
+    assert_equal nil, new_todo.show_from
+  end
+  
 end</diff>
      <filename>test/functional/recurring_todos_controller_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -70,7 +70,7 @@ class TodosControllerTest &lt; Test::Rails::TestCase
     login_as(:admin_user)
     xhr :post, :destroy, :id =&gt; 1, :_source_view =&gt; 'todo'
     assert_rjs :page, &quot;todo_1&quot;, :remove
-    #assert_rjs :replace_html, &quot;badge-count&quot;, '9' 
+    # #assert_rjs :replace_html, &quot;badge-count&quot;, '9'
   end
   
   def test_create_todo
@@ -90,11 +90,11 @@ class TodosControllerTest &lt; Test::Rails::TestCase
 
   def test_fail_to_create_todo_via_xml
     login_as(:admin_user)
-    #try to create with no context, which is not valid
+    # #try to create with no context, which is not valid
     put :create, :format =&gt; &quot;xml&quot;, &quot;request&quot; =&gt; { &quot;project_name&quot;=&gt;&quot;Build a working time machine&quot;, &quot;todo&quot;=&gt;{&quot;notes&quot;=&gt;&quot;&quot;, &quot;description&quot;=&gt;&quot;Call Warren Buffet to find out how much he makes per day&quot;, &quot;due&quot;=&gt;&quot;30/11/2006&quot;}, &quot;tag_list&quot;=&gt;&quot;foo bar&quot; }
     assert_response 422
     assert_xml_select &quot;errors&quot; do
-       assert_xml_select &quot;error&quot;, &quot;Context can't be blank&quot;
+      assert_xml_select &quot;error&quot;, &quot;Context can't be blank&quot;
     end
   end
   
@@ -180,7 +180,7 @@ class TodosControllerTest &lt; Test::Rails::TestCase
     login_as(:admin_user)
     get :index, { :format =&gt; &quot;rss&quot; }
     assert_equal 'application/rss+xml', @response.content_type
-    #puts @response.body
+    # #puts @response.body
 
     assert_xml_select 'rss[version=&quot;2.0&quot;]' do
       assert_select 'channel' do
@@ -237,7 +237,7 @@ class TodosControllerTest &lt; Test::Rails::TestCase
     login_as :admin_user
     get :index, { :format =&gt; &quot;atom&quot; }
     assert_equal 'application/atom+xml', @response.content_type
-    #puts @response.body
+    # #puts @response.body
 
     assert_xml_select 'feed[xmlns=&quot;http://www.w3.org/2005/Atom&quot;]' do
       assert_xml_select '&gt;title', 'Tracks Actions'
@@ -273,7 +273,7 @@ class TodosControllerTest &lt; Test::Rails::TestCase
     get :index, { :format =&gt; &quot;txt&quot; }
     assert_equal 'text/plain', @response.content_type
     assert !(/&amp;nbsp;/.match(@response.body))
-    #puts @response.body
+    # #puts @response.body
   end
 
   def test_text_feed_not_accessible_to_anonymous_user_without_token
@@ -299,7 +299,7 @@ class TodosControllerTest &lt; Test::Rails::TestCase
     get :index, { :format =&gt; &quot;ics&quot; }
     assert_equal 'text/calendar', @response.content_type
     assert !(/&amp;nbsp;/.match(@response.body))
-    #puts @response.body
+    # #puts @response.body
   end
   
   def test_mobile_index_uses_text_html_content_type
@@ -317,10 +317,10 @@ class TodosControllerTest &lt; Test::Rails::TestCase
   def test_mobile_create_action_creates_a_new_todo
     login_as(:admin_user)
     post :create, {&quot;format&quot;=&gt;&quot;m&quot;, &quot;todo&quot;=&gt;{&quot;context_id&quot;=&gt;&quot;2&quot;,
-                   &quot;due(1i)&quot;=&gt;&quot;2007&quot;, &quot;due(2i)&quot;=&gt;&quot;1&quot;, &quot;due(3i)&quot;=&gt;&quot;2&quot;,
-                   &quot;show_from(1i)&quot;=&gt;&quot;&quot;, &quot;show_from(2i)&quot;=&gt;&quot;&quot;, &quot;show_from(3i)&quot;=&gt;&quot;&quot;,
-                   &quot;project_id&quot;=&gt;&quot;1&quot;, 
-                   &quot;notes&quot;=&gt;&quot;test notes&quot;, &quot;description&quot;=&gt;&quot;test_mobile_create_action&quot;, &quot;state&quot;=&gt;&quot;0&quot;}}
+        &quot;due(1i)&quot;=&gt;&quot;2007&quot;, &quot;due(2i)&quot;=&gt;&quot;1&quot;, &quot;due(3i)&quot;=&gt;&quot;2&quot;,
+        &quot;show_from(1i)&quot;=&gt;&quot;&quot;, &quot;show_from(2i)&quot;=&gt;&quot;&quot;, &quot;show_from(3i)&quot;=&gt;&quot;&quot;,
+        &quot;project_id&quot;=&gt;&quot;1&quot;, 
+        &quot;notes&quot;=&gt;&quot;test notes&quot;, &quot;description&quot;=&gt;&quot;test_mobile_create_action&quot;, &quot;state&quot;=&gt;&quot;0&quot;}}
     t = Todo.find_by_description(&quot;test_mobile_create_action&quot;)
     assert_not_nil t
     assert_equal 2, t.context_id
@@ -334,20 +334,20 @@ class TodosControllerTest &lt; Test::Rails::TestCase
   def test_mobile_create_action_redirects_to_mobile_home_page_when_successful
     login_as(:admin_user)
     post :create, {&quot;format&quot;=&gt;&quot;m&quot;, &quot;todo&quot;=&gt;{&quot;context_id&quot;=&gt;&quot;2&quot;,
-                   &quot;due(1i)&quot;=&gt;&quot;2007&quot;, &quot;due(2i)&quot;=&gt;&quot;1&quot;, &quot;due(3i)&quot;=&gt;&quot;2&quot;,
-                   &quot;show_from(1i)&quot;=&gt;&quot;&quot;, &quot;show_from(2i)&quot;=&gt;&quot;&quot;, &quot;show_from(3i)&quot;=&gt;&quot;&quot;,
-                   &quot;project_id&quot;=&gt;&quot;1&quot;, 
-                   &quot;notes&quot;=&gt;&quot;test notes&quot;, &quot;description&quot;=&gt;&quot;test_mobile_create_action&quot;, &quot;state&quot;=&gt;&quot;0&quot;}}
+        &quot;due(1i)&quot;=&gt;&quot;2007&quot;, &quot;due(2i)&quot;=&gt;&quot;1&quot;, &quot;due(3i)&quot;=&gt;&quot;2&quot;,
+        &quot;show_from(1i)&quot;=&gt;&quot;&quot;, &quot;show_from(2i)&quot;=&gt;&quot;&quot;, &quot;show_from(3i)&quot;=&gt;&quot;&quot;,
+        &quot;project_id&quot;=&gt;&quot;1&quot;, 
+        &quot;notes&quot;=&gt;&quot;test notes&quot;, &quot;description&quot;=&gt;&quot;test_mobile_create_action&quot;, &quot;state&quot;=&gt;&quot;0&quot;}}
     assert_redirected_to '/m'
   end
 
   def test_mobile_create_action_renders_new_template_when_save_fails
     login_as(:admin_user)
     post :create, {&quot;format&quot;=&gt;&quot;m&quot;, &quot;todo&quot;=&gt;{&quot;context_id&quot;=&gt;&quot;2&quot;,
-                   &quot;due(1i)&quot;=&gt;&quot;2007&quot;, &quot;due(2i)&quot;=&gt;&quot;1&quot;, &quot;due(3i)&quot;=&gt;&quot;2&quot;,
-                   &quot;show_from(1i)&quot;=&gt;&quot;&quot;, &quot;show_from(2i)&quot;=&gt;&quot;&quot;, &quot;show_from(3i)&quot;=&gt;&quot;&quot;,
-                   &quot;project_id&quot;=&gt;&quot;1&quot;, 
-                   &quot;notes&quot;=&gt;&quot;test notes&quot;, &quot;state&quot;=&gt;&quot;0&quot;}, &quot;tag_list&quot;=&gt;&quot;test, test2&quot;}
+        &quot;due(1i)&quot;=&gt;&quot;2007&quot;, &quot;due(2i)&quot;=&gt;&quot;1&quot;, &quot;due(3i)&quot;=&gt;&quot;2&quot;,
+        &quot;show_from(1i)&quot;=&gt;&quot;&quot;, &quot;show_from(2i)&quot;=&gt;&quot;&quot;, &quot;show_from(3i)&quot;=&gt;&quot;&quot;,
+        &quot;project_id&quot;=&gt;&quot;1&quot;, 
+        &quot;notes&quot;=&gt;&quot;test notes&quot;, &quot;state&quot;=&gt;&quot;0&quot;}, &quot;tag_list&quot;=&gt;&quot;test, test2&quot;}
     assert_template 'todos/new'
   end
 
@@ -357,4 +357,25 @@ class TodosControllerTest &lt; Test::Rails::TestCase
     assert_equal '&quot;{\\&quot;Build a working time machine\\&quot;: \\&quot;lab\\&quot;}&quot;', assigns(:default_project_context_name_map)
   end
 
+  def test_toggle_check_on_recurring_todo
+    login_as(:admin_user)
+    
+    # link todo_1 and recurring_todo_1
+    recurring_todo_1 = RecurringTodo.find(1)
+    todo_1 = Todo.find(1)
+    todo_1.recurring_todo_id = recurring_todo_1.id
+    
+    # update todo_1
+    assert todo_1.save
+    
+    # mark todo_1 as complete by toggle_check
+    xhr :post, :toggle_check, :id =&gt; 1, :_source_view =&gt; 'todo' 
+    todo_1.reload
+    assert todo_1.completed?
+
+    # check there is a new todo linked to the recurring pattern
+    next_todo = Todo.find_by_recurring_todo_id(recurring_todo_1.id)
+    assert_equal &quot;Call Bill Gates every day&quot;, next_todo.description
+  end
+  
 end</diff>
      <filename>test/functional/todos_controller_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b076ae46f8146f67ab84fe0bbe3bd1c7dd153a94</id>
    </parent>
  </parents>
  <author>
    <name>Reinier Balt</name>
    <email>lrbalt@gmail.com</email>
  </author>
  <url>http://github.com/bsag/tracks/commit/666f524b16c847cf8b3d241636e57087097306dc</url>
  <id>666f524b16c847cf8b3d241636e57087097306dc</id>
  <committed-date>2008-08-19T05:58:45-07:00</committed-date>
  <authored-date>2008-08-19T05:58:45-07:00</authored-date>
  <message>add functional tests for recurring todos

includes a test for rec todos with due date in future and show_from in past</message>
  <tree>aa447b7a43d6779bdea91b425eadbf69b92acc8f</tree>
  <committer>
    <name>Reinier Balt</name>
    <email>lrbalt@gmail.com</email>
  </committer>
</commit>
