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 !
add functional tests for recurring todos

includes a test for rec todos with due date in future and show_from in past
lrbalt (author)
Tue Aug 19 05:58:45 -0700 2008
commit  666f524b16c847cf8b3d241636e57087097306dc
tree    aa447b7a43d6779bdea91b425eadbf69b92acc8f
parent  b076ae46f8146f67ab84fe0bbe3bd1c7dd153a94
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@ module AuthenticatedTestHelper
0
   def login_as(user)
0
     @request.session['user_id'] = user ? users(user).id : nil
0
   end
0
-  
0
+
0
   def content_type(type)
0
     @request.env['Content-Type'] = type
0
   end
...
17
18
19
 
 
 
 
 
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
0
@@ -17,6 +17,107 @@ class RecurringTodosControllerTest < ActionController::TestCase
0
     login_as(:admin_user)
0
     xhr :post, :destroy, :id => 1, :_source_view => 'todo'
0
     assert_rjs :page, "recurring_todo_1", :remove
0
+    begin 
0
+      rc = RecurringTodo.find(1)
0
+    rescue
0
+      rc = nil      
0
+    end
0
+    assert_nil rc
0
   end
0
+  
0
+  def test_new_recurring_todo
0
+    login_as(:admin_user)
0
+    orig_rt_count = RecurringTodo.count
0
+    orig_todo_count = Todo.count
0
+    put :create,       
0
+      "context_name"=>"library", 
0
+      "project_name"=>"Build a working time machine", 
0
+      "recurring_todo" => 
0
+      {
0
+      "daily_every_x_days"=>"1", 
0
+      "daily_selector"=>"daily_every_x_day", 
0
+      "description"=>"new recurring pattern", 
0
+      "end_date" => "31/08/2010",
0
+      "ends_on" => "ends_on_end_date",
0
+      "monthly_day_of_week" => "1",
0
+      "monthly_every_x_day" => "18",
0
+      "monthly_every_x_month2" => "1",
0
+      "monthly_every_x_month" => "1",
0
+      "monthly_every_xth_day"=>"1",
0
+      "monthly_selector"=>"monthly_every_x_day",
0
+      "notes"=>"with some notes",
0
+      "number_of_occurences" => "",
0
+      "recurring_period"=>"yearly",
0
+      "recurring_show_days_before"=>"10",
0
+      "recurring_target"=>"due_date",
0
+      "start_from"=>"18/08/2008",
0
+      "weekly_every_x_week"=>"1",
0
+      "weekly_return_monday"=>"m",
0
+      "yearly_day_of_week"=>"1",
0
+      "yearly_every_x_day"=>"8",
0
+      "yearly_every_xth_day"=>"1",
0
+      "yearly_month_of_year2"=>"8",
0
+      "yearly_month_of_year"=>"6",
0
+      "yearly_selector"=>"yearly_every_x_day"
0
+    }, 
0
+      "tag_list"=>"one, two, three, four"
0
+    
0
+    # check new recurring todo added
0
+    assert_equal orig_rt_count+1, RecurringTodo.count  
0
+    # check new todo added
0
+    assert_equal orig_todo_count+1, Todo.count
0
+  end
0
+  
0
+  def test_recurring_todo_toggle_check
0
+    # the test fixtures did add recurring_todos but not the corresponding todos,
0
+    # so we check complete and uncheck to force creation of a todo from the
0
+    # pattern
0
+    login_as(:admin_user)
0
 
0
+    # mark as complete
0
+    xhr :post, :toggle_check, :id=>1, :_source_view=>""
0
+    recurring_todo_1 = RecurringTodo.find(1)
0
+    assert recurring_todo_1.completed?
0
+    
0
+    todo_count = Todo.count
0
+    
0
+    # mark as active
0
+    xhr :post, :toggle_check, :id=>1, :_source_view=>""    
0
+    recurring_todo_1.reload
0
+    assert recurring_todo_1.active?
0
+    
0
+    # by making  active, a new todo should be created from the pattern
0
+    assert_equal todo_count+1, Todo.count
0
+    
0
+    # find the new todo and check its description
0
+    new_todo = Todo.find_by_recurring_todo_id 1
0
+    assert_equal "Call Bill Gates every day", new_todo.description
0
+  end
0
+
0
+  def test_creating_recurring_todo_with_show_from_in_past
0
+    login_as(:admin_user)
0
+    
0
+    @yearly = RecurringTodo.find(5) # yearly on june 8th
0
+    
0
+    # change due date in four days from now and show from 10 days before, i.e. 6
0
+    # days ago
0
+    target_date = Time.now.utc + 4.days
0
+    @yearly.every_other1 = target_date.day
0
+    @yearly.every_other2 = target_date.month
0
+    @yearly.show_from_delta = 10
0
+    assert @yearly.save
0
+    
0
+    # toggle twice to force generation of new todo
0
+    xhr :post, :toggle_check, :id=>5, :_source_view=>""
0
+    xhr :post, :toggle_check, :id=>5, :_source_view=>""
0
+
0
+    new_todo = Todo.find_by_recurring_todo_id 5
0
+    
0
+    # due date should be the target_date
0
+    assert_equal Time.utc(target_date.year, target_date.month, target_date.day), new_todo.due
0
+    
0
+    # show_from should be nil since now+4.days-10.days is in the past
0
+    assert_equal nil, new_todo.show_from
0
+  end
0
+  
0
 end
...
70
71
72
73
 
74
75
76
...
90
91
92
93
 
94
95
96
97
 
98
99
100
...
180
181
182
183
 
184
185
186
...
237
238
239
240
 
241
242
243
...
273
274
275
276
 
277
278
279
...
299
300
301
302
 
303
304
305
...
317
318
319
320
321
322
323
 
 
 
 
324
325
326
...
334
335
336
337
338
339
340
 
 
 
 
341
342
343
344
345
346
347
348
349
350
 
 
 
 
351
352
353
...
357
358
359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
...
70
71
72
 
73
74
75
76
...
90
91
92
 
93
94
95
96
 
97
98
99
100
...
180
181
182
 
183
184
185
186
...
237
238
239
 
240
241
242
243
...
273
274
275
 
276
277
278
279
...
299
300
301
 
302
303
304
305
...
317
318
319
 
 
 
 
320
321
322
323
324
325
326
...
334
335
336
 
 
 
 
337
338
339
340
341
342
343
344
345
346
 
 
 
 
347
348
349
350
351
352
353
...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
0
@@ -70,7 +70,7 @@ class TodosControllerTest < Test::Rails::TestCase
0
     login_as(:admin_user)
0
     xhr :post, :destroy, :id => 1, :_source_view => 'todo'
0
     assert_rjs :page, "todo_1", :remove
0
-    #assert_rjs :replace_html, "badge-count", '9' 
0
+    # #assert_rjs :replace_html, "badge-count", '9'
0
   end
0
   
0
   def test_create_todo
0
@@ -90,11 +90,11 @@ class TodosControllerTest < Test::Rails::TestCase
0
 
0
   def test_fail_to_create_todo_via_xml
0
     login_as(:admin_user)
0
-    #try to create with no context, which is not valid
0
+    # #try to create with no context, which is not valid
0
     put :create, :format => "xml", "request" => { "project_name"=>"Build a working time machine", "todo"=>{"notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"30/11/2006"}, "tag_list"=>"foo bar" }
0
     assert_response 422
0
     assert_xml_select "errors" do
0
-       assert_xml_select "error", "Context can't be blank"
0
+      assert_xml_select "error", "Context can't be blank"
0
     end
0
   end
0
   
0
@@ -180,7 +180,7 @@ class TodosControllerTest < Test::Rails::TestCase
0
     login_as(:admin_user)
0
     get :index, { :format => "rss" }
0
     assert_equal 'application/rss+xml', @response.content_type
0
-    #puts @response.body
0
+    # #puts @response.body
0
 
0
     assert_xml_select 'rss[version="2.0"]' do
0
       assert_select 'channel' do
0
@@ -237,7 +237,7 @@ class TodosControllerTest < Test::Rails::TestCase
0
     login_as :admin_user
0
     get :index, { :format => "atom" }
0
     assert_equal 'application/atom+xml', @response.content_type
0
-    #puts @response.body
0
+    # #puts @response.body
0
 
0
     assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
0
       assert_xml_select '>title', 'Tracks Actions'
0
@@ -273,7 +273,7 @@ class TodosControllerTest < Test::Rails::TestCase
0
     get :index, { :format => "txt" }
0
     assert_equal 'text/plain', @response.content_type
0
     assert !(/&nbsp;/.match(@response.body))
0
-    #puts @response.body
0
+    # #puts @response.body
0
   end
0
 
0
   def test_text_feed_not_accessible_to_anonymous_user_without_token
0
@@ -299,7 +299,7 @@ class TodosControllerTest < Test::Rails::TestCase
0
     get :index, { :format => "ics" }
0
     assert_equal 'text/calendar', @response.content_type
0
     assert !(/&nbsp;/.match(@response.body))
0
-    #puts @response.body
0
+    # #puts @response.body
0
   end
0
   
0
   def test_mobile_index_uses_text_html_content_type
0
@@ -317,10 +317,10 @@ class TodosControllerTest < Test::Rails::TestCase
0
   def test_mobile_create_action_creates_a_new_todo
0
     login_as(:admin_user)
0
     post :create, {"format"=>"m", "todo"=>{"context_id"=>"2",
0
-                   "due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
0
-                   "show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
0
-                   "project_id"=>"1", 
0
-                   "notes"=>"test notes", "description"=>"test_mobile_create_action", "state"=>"0"}}
0
+        "due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
0
+        "show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
0
+        "project_id"=>"1", 
0
+        "notes"=>"test notes", "description"=>"test_mobile_create_action", "state"=>"0"}}
0
     t = Todo.find_by_description("test_mobile_create_action")
0
     assert_not_nil t
0
     assert_equal 2, t.context_id
0
@@ -334,20 +334,20 @@ class TodosControllerTest < Test::Rails::TestCase
0
   def test_mobile_create_action_redirects_to_mobile_home_page_when_successful
0
     login_as(:admin_user)
0
     post :create, {"format"=>"m", "todo"=>{"context_id"=>"2",
0
-                   "due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
0
-                   "show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
0
-                   "project_id"=>"1", 
0
-                   "notes"=>"test notes", "description"=>"test_mobile_create_action", "state"=>"0"}}
0
+        "due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
0
+        "show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
0
+        "project_id"=>"1", 
0
+        "notes"=>"test notes", "description"=>"test_mobile_create_action", "state"=>"0"}}
0
     assert_redirected_to '/m'
0
   end
0
 
0
   def test_mobile_create_action_renders_new_template_when_save_fails
0
     login_as(:admin_user)
0
     post :create, {"format"=>"m", "todo"=>{"context_id"=>"2",
0
-                   "due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
0
-                   "show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
0
-                   "project_id"=>"1", 
0
-                   "notes"=>"test notes", "state"=>"0"}, "tag_list"=>"test, test2"}
0
+        "due(1i)"=>"2007", "due(2i)"=>"1", "due(3i)"=>"2",
0
+        "show_from(1i)"=>"", "show_from(2i)"=>"", "show_from(3i)"=>"",
0
+        "project_id"=>"1", 
0
+        "notes"=>"test notes", "state"=>"0"}, "tag_list"=>"test, test2"}
0
     assert_template 'todos/new'
0
   end
0
 
0
@@ -357,4 +357,25 @@ class TodosControllerTest < Test::Rails::TestCase
0
     assert_equal '"{\\"Build a working time machine\\": \\"lab\\"}"', assigns(:default_project_context_name_map)
0
   end
0
 
0
+  def test_toggle_check_on_recurring_todo
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(1)
0
+    todo_1.recurring_todo_id = recurring_todo_1.id
0
+    
0
+    # update todo_1
0
+    assert todo_1.save
0
+    
0
+    # mark todo_1 as complete by toggle_check
0
+    xhr :post, :toggle_check, :id => 1, :_source_view => 'todo' 
0
+    todo_1.reload
0
+    assert todo_1.completed?
0
+
0
+    # check there is a new todo linked to the recurring pattern
0
+    next_todo = Todo.find_by_recurring_todo_id(recurring_todo_1.id)
0
+    assert_equal "Call Bill Gates every day", next_todo.description
0
+  end
0
+  
0
 end

Comments