Fix #1045. The tests broke because of this fix cfc6d117b8. This exposed a new corner case that I fixed and created a test for. Also a small refactoring.

This commit is contained in:
Reinier Balt 2010-07-29 16:37:22 +02:00
parent 9a243b015a
commit 3d75cd2457
3 changed files with 42 additions and 36 deletions

View file

@ -1,22 +1,26 @@
<%
def today
Time.zone.now.beginning_of_day.to_s(:db)
Time.zone.now.beginning_of_day.to_s(:db)
end
def next_week
1.week.from_now.beginning_of_day.to_s(:db)
1.week.from_now.beginning_of_day.to_s(:db)
end
def last_week
1.week.ago.beginning_of_day.to_s(:db)
1.week.ago.beginning_of_day.to_s(:db)
end
def two_weeks_ago
2.weeks.ago.beginning_of_day.to_s(:db)
2.weeks.ago.beginning_of_day.to_s(:db)
end
def two_weeks_hence
2.weeks.from_now.beginning_of_day.to_s(:db)
2.weeks.from_now.beginning_of_day.to_s(:db)
end
def way_back
Time.zone.local(2008,1,1)
end
%>
@ -29,7 +33,7 @@ call_bill_gates_every_day:
description: Call Bill Gates every day
notes: ~
state: active
start_from: <%= last_week %>
start_from: <%= way_back %>
ends_on: no_end_date
end_date: ~
number_of_occurences: ~
@ -83,7 +87,7 @@ call_bill_gates_every_week:
description: Call Bill Gates every week
notes: ~
state: active
start_from: <%= today %>
start_from: <%= way_back %>
ends_on: no_end_date
end_date: ~
number_of_occurences: ~
@ -110,7 +114,7 @@ check_with_bill_every_last_friday_of_month:
description: Check with Bill every last friday of the month
notes: ~
state: active
start_from: <%= today %>
start_from: <%= way_back %>
ends_on: no_end_date
end_date: ~
number_of_occurences: ~
@ -137,7 +141,7 @@ birthday_reinier:
description: Congratulate Reinier on his birthday
notes: ~
state: active
start_from: <%= today %>
start_from: <%= way_back %>
ends_on: no_end_date
end_date: ~
number_of_occurences: ~

View file

@ -207,11 +207,27 @@ class RecurringTodoTest < ActiveSupport::TestCase
# same month, after second wednesday
due_date = @yearly.get_due_date(Time.zone.local(2008,6,12)) # june 7th
assert_equal Time.zone.local(2009,6,10), due_date # june 10th
# test handling of nil
end
def test_next_todo_without_previous_todo
# test handling of nil as previous
#
# start_from is way_back
due_date1 = @yearly.get_due_date(nil)
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
assert_equal due_date1, due_date2
# start_from is in the future
@yearly.start_from = Time.now.utc + 1.week
due_date1 = @yearly.get_due_date(nil)
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
assert_equal due_date1, due_date2
# start_from is nil
@yearly.start_from = nil
due_date1 = @yearly.get_due_date(nil)
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
assert_equal due_date1, due_date2
end
def test_last_sunday_of_march