<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>db/migrate/20090531111711_add_show_always_to_recurring_todo.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -311,6 +311,10 @@ class RecurringTodo &lt; ActiveRecord::Base
     self.show_from_delta=days
   end
   
+  def recurring_show_always=(value)
+    self.show_always=value
+  end
+  
   def recurrence_pattern
     case recurring_period
     when 'daily'
@@ -380,9 +384,12 @@ class RecurringTodo &lt; ActiveRecord::Base
   def get_show_from_date(previous)
     case self.target 
     when 'due_date'
-      # so set show from date relative to due date unless show_from_delta is
-      # zero / nil
-      return (self.show_from_delta == 0 || self.show_from_delta.nil?) ? nil : get_due_date(previous) - self.show_from_delta.days
+      # so set show from date relative to due date unless show_always is true or show_from_delta is nil  
+      if self.show_always? or self.show_from_delta.nil?
+        nil
+      else
+        get_due_date(previous) - self.show_from_delta.days
+      end
     when 'show_from_date'
       # Leave due date empty
       return get_next_date(previous)</diff>
      <filename>app/models/recurring_todo.rb</filename>
    </modified>
    <modified>
      <diff>@@ -134,10 +134,12 @@
     &lt;/div&gt;
     &lt;div id=&quot;recurring_target&quot;&gt;
       &lt;label&gt;Set recurrence on&lt;/label&gt;&lt;br/&gt;
-      &lt;%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @recurring_todo.target == 'due_date')%&gt; the date that the todo is due.
-      Show the todo &lt;%=
-      text_field_tag( 'recurring_todo[recurring_show_days_before]', @recurring_todo.show_from_delta, {&quot;size&quot; =&gt; 3, &quot;tabindex&quot; =&gt; 12}) %&gt;
-      days before the todo is due (0=show always)&lt;br/&gt;
+      &lt;%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @recurring_todo.target == 'due_date')%&gt; the date that the todo is due. Show the todo:
+        &lt;%= radio_button_tag('recurring_todo[recurring_show_always]', '1', @recurring_todo.show_always?)%&gt; always
+        &lt;%= radio_button_tag('recurring_todo[recurring_show_always]', '0', !@recurring_todo.show_always?)%&gt;
+          &lt;%= text_field_tag( 'recurring_todo[recurring_show_days_before]', @recurring_todo.show_from_delta, {&quot;size&quot; =&gt; 3, &quot;tabindex&quot; =&gt; 12}) %&gt;
+          days before the todo is due
+          &lt;br/&gt;
       &lt;%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', @recurring_todo.target == 'show_from_date')%&gt; the date todo comes from tickler (no due date set)&lt;br/&gt;
       &lt;br/&gt;
     &lt;/div&gt;</diff>
      <filename>app/views/recurring_todos/_edit_form.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -132,10 +132,12 @@
     &lt;/div&gt;
     &lt;div id=&quot;recurring_target&quot;&gt;
       &lt;label&gt;Set recurrence on&lt;/label&gt;&lt;br/&gt;
-      &lt;%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', true)%&gt; the date that the todo is due.
-      Show the todo &lt;%=
-      text_field_tag( 'recurring_todo[recurring_show_days_before]', &quot;0&quot;, {&quot;size&quot; =&gt; 3, &quot;tabindex&quot; =&gt; 12}) %&gt;
-      days before the todo is due (0=show always)&lt;br/&gt;
+      &lt;%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', true)%&gt; the date that the todo is due. Show the todo:
+        &lt;%= radio_button_tag('recurring_todo[recurring_show_always]', '1', true)%&gt; always
+        &lt;%= radio_button_tag('recurring_todo[recurring_show_always]', '0', false)%&gt;
+          &lt;%= text_field_tag( 'recurring_todo[recurring_show_days_before]', &quot;0&quot;, {&quot;size&quot; =&gt; 3, &quot;tabindex&quot; =&gt; 12}) %&gt;
+          days before the todo is due
+          &lt;br/&gt;
       &lt;%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', false)%&gt; the date todo comes from tickler (no due date set)&lt;br/&gt;
       &lt;br/&gt;
     &lt;/div&gt;</diff>
      <filename>app/views/recurring_todos/_recurring_todo_form.erb</filename>
    </modified>
    <modified>
      <diff>@@ -180,4 +180,56 @@ class RecurringTodosControllerTest &lt; ActionController::TestCase
     assert_equal Time.zone.local(2013,3,31), new_todo.due
   end
     
+  def test_recurring_todo_with_due_date_and_show_always
+    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;&quot;,
+      &quot;ends_on&quot; =&gt; &quot;no_end_date&quot;,
+      &quot;monthly_day_of_week&quot; =&gt; &quot;1&quot;,
+      &quot;monthly_every_x_day&quot; =&gt; &quot;22&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_always&quot;=&gt;&quot;1&quot;,
+      &quot;recurring_show_days_before&quot;=&gt;&quot;0&quot;,
+      &quot;recurring_target&quot;=&gt;&quot;due_date&quot;,
+      &quot;start_from&quot;=&gt;&quot;1/10/2012&quot;,  # adjust after 2012
+      &quot;weekly_every_x_week&quot;=&gt;&quot;1&quot;,
+      &quot;weekly_return_monday&quot;=&gt;&quot;w&quot;,
+      &quot;yearly_day_of_week&quot;=&gt;&quot;0&quot;,
+      &quot;yearly_every_x_day&quot;=&gt;&quot;22&quot;,
+      &quot;yearly_every_xth_day&quot;=&gt;&quot;5&quot;,
+      &quot;yearly_month_of_year2&quot;=&gt;&quot;3&quot;,
+      &quot;yearly_month_of_year&quot;=&gt;&quot;10&quot;,
+      &quot;yearly_selector&quot;=&gt;&quot;yearly_every_xth_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
+
+    # find the newly created recurring todo
+    recurring_todo = RecurringTodo.find_by_description(&quot;new recurring pattern&quot;)
+    assert !recurring_todo.nil?
+    
+    assert_equal &quot;due_date&quot;, recurring_todo.target
+    assert_equal true, recurring_todo.show_always?
+  end
 end</diff>
      <filename>test/functional/recurring_todos_controller_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -67,12 +67,22 @@ class RecurringTodoTest &lt; Test::Rails::TestCase
     assert_equal @today+1.day, @every_day.get_show_from_date(@today)
     
     @every_day.target='due_date'
-    # when target on due_date, show_from is relative to due date unless delta=0
+    # when target on due_date, show_from is relative to due date unless show_always is true
+    @every_day.show_always = true
     assert_equal nil, @every_day.get_show_from_date(@today-1.days)
 
+    @every_day.show_always = false
     @every_day.show_from_delta=10
     assert_equal @today, @every_day.get_show_from_date(@today+9.days) #today+1+9-10
     
+    # when show_from is 0, show_from is the same day it's due
+    @every_day.show_from_delta=0
+    assert_equal @every_day.get_due_date(@today+9.days), @every_day.get_show_from_date(@today+9.days)
+    
+    # when show_from is nil, show always (happend in tests)
+    @every_day.show_from_delta=nil
+    assert_equal nil, @every_day.get_show_from_date(@today+9.days)
+    
     # TODO: show_from has no use case for daily pattern. Need to test on
     # weekly/monthly/yearly
   end</diff>
      <filename>test/unit/recurring_todo_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8002eef8abd0642272e3ab19ca00ff235e0910cc</id>
    </parent>
  </parents>
  <author>
    <name>piglop</name>
    <email>mike@lepton.fr</email>
  </author>
  <url>http://github.com/bsag/tracks/commit/4e1e18da0fca66ffe8ca56026a36879dc2327459</url>
  <id>4e1e18da0fca66ffe8ca56026a36879dc2327459</id>
  <committed-date>2009-06-02T10:36:20-07:00</committed-date>
  <authored-date>2009-05-31T05:15:01-07:00</authored-date>
  <message>fixed #781:
* added a &quot;show always&quot; radio to the recurring todo forms
* added a show_always flag to recurring todos
* created a migration to convert existing recurring todos where show_from_delta==0
* recurring todos where show_from_delta is 0 are now shown the same day they're due

Signed-off-by: Reinier Balt &lt;lrbalt@gmail.com&gt;</message>
  <tree>a56a22f34cfe74ee234c673d3119c32e60800f6a</tree>
  <committer>
    <name>Reinier Balt</name>
    <email>lrbalt@gmail.com</email>
  </committer>
</commit>
