fix issue where deleting a recurring todo from tickler results in an error

This commit is contained in:
Reinier Balt 2008-08-01 15:37:10 +02:00
parent dcac7611ed
commit 9acb01e9cb
3 changed files with 7 additions and 5 deletions

View file

@ -675,8 +675,9 @@ class TodosController < ApplicationController
@recurring_todo = nil @recurring_todo = nil
if @todo.from_recurring_todo? if @todo.from_recurring_todo?
@recurring_todo = current_user.recurring_todos.find(@todo.recurring_todo_id) @recurring_todo = current_user.recurring_todos.find(@todo.recurring_todo_id)
if @recurring_todo.active? && @recurring_todo.has_next_todo(@todo.due) date_to_check = @todo.due.nil? ? @todo.show_from : @todo.due
date = @todo.due >= Date.today() ? @todo.due : Date.today()-1.day if @recurring_todo.active? && @recurring_todo.has_next_todo(date_to_check)
date = date_to_check >= Date.today() ? date_to_check : Date.today()-1.day
@new_recurring_todo = create_todo_from_recurring_todo(@recurring_todo, date) @new_recurring_todo = create_todo_from_recurring_todo(@recurring_todo, date)
end end
end end

View file

@ -466,7 +466,7 @@ class RecurringTodo < ActiveRecord::Base
when 1 # relative weekday of a month when 1 # relative weekday of a month
the_next = get_xth_day_of_month(self.every_other3, self.every_count, start.month, start.year) the_next = get_xth_day_of_month(self.every_other3, self.every_count, start.month, start.year)
if the_next.nil? || the_next < start if the_next.nil? || the_next <= start
# the nth day is already passed in this month, go to next month and try # the nth day is already passed in this month, go to next month and try
# again # again
the_next = the_next+n.months the_next = the_next+n.months

View file

@ -74,6 +74,7 @@ class RecurringTodoTest < Test::Rails::TestCase
# check show from get the next day # check show from get the next day
assert_equal @today, @every_day.get_show_from_date(@today-1.days) assert_equal @today, @every_day.get_show_from_date(@today-1.days)
assert_equal @today+1.day, @every_day.get_show_from_date(@today)
@every_day.target='due_date' @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 delta=0
@ -146,7 +147,7 @@ class RecurringTodoTest < Test::Rails::TestCase
assert_equal Time.utc(2008,6,27), due_date assert_equal Time.utc(2008,6,27), due_date
friday_is_last_day_of_month = Time.utc(2008,10,31) friday_is_last_day_of_month = Time.utc(2008,10,31)
due_date = @monthly_every_last_friday.get_due_date(friday_is_last_day_of_month ) due_date = @monthly_every_last_friday.get_due_date(friday_is_last_day_of_month-1.day )
assert_equal friday_is_last_day_of_month , due_date assert_equal friday_is_last_day_of_month , due_date
@monthly_every_third_friday = @monthly_every_last_friday @monthly_every_third_friday = @monthly_every_last_friday