mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-29 05:18:49 +01:00
fix #1270. if start-from fits the recurrence pattern, the first todo should use the start-from date
this is use-case 2 mentioned in the ticket.
This commit is contained in:
parent
3a2af7caf2
commit
56b884055f
4 changed files with 53 additions and 5 deletions
|
|
@ -541,14 +541,13 @@ class RecurringTodo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def get_monthly_date(previous)
|
||||
|
||||
start = determine_start(previous)
|
||||
day = self.every_other1
|
||||
n = self.every_other2
|
||||
|
||||
case self.recurrence_selector
|
||||
when 0 # specific day of the month
|
||||
if start.mday >= day
|
||||
if start.mday > day
|
||||
# there is no next day n in this month, search in next month
|
||||
#
|
||||
# start += n.months
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
"recurring_show_days_before"=>"0",
|
||||
"recurring_target"=>"due_date",
|
||||
"recurring_show_always" => "1",
|
||||
"start_from"=>"1/10/2012", # adjust after 2012
|
||||
"start_from"=>"1/10/2012",
|
||||
"weekly_every_x_week"=>"1",
|
||||
"weekly_return_monday"=>"w",
|
||||
"yearly_day_of_week"=>"0",
|
||||
|
|
@ -235,6 +235,52 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
|||
assert_equal true, recurring_todo.show_always?
|
||||
end
|
||||
|
||||
def test_start_on_monthly_rec_todo
|
||||
Timecop.travel(Time.local(2012,1,1)) do
|
||||
|
||||
login_as(:admin_user)
|
||||
|
||||
put :create,
|
||||
"context_name"=>"library",
|
||||
"project_name"=>"Build a working time machine",
|
||||
"recurring_todo" =>
|
||||
{
|
||||
"daily_every_x_days"=>"1",
|
||||
"daily_selector"=>"daily_every_x_day",
|
||||
"description"=>"new recurring pattern",
|
||||
"end_date" => nil,
|
||||
"ends_on" => "no_end_date",
|
||||
"monthly_day_of_week" => "2",
|
||||
"monthly_every_x_day" => "2",
|
||||
"monthly_every_x_month2" => "1",
|
||||
"monthly_every_x_month" => "3",
|
||||
"monthly_every_xth_day"=>"1",
|
||||
"monthly_selector"=>"monthly_every_x_day",
|
||||
"notes"=>"with some notes",
|
||||
"number_of_occurences" => nil,
|
||||
"recurring_period"=>"monthly",
|
||||
"recurring_show_days_before"=>"0",
|
||||
"recurring_target"=>"show_from_date",
|
||||
"recurring_show_always" => "1",
|
||||
"start_from"=>"2/1/2013",
|
||||
"weekly_every_x_week"=>"1",
|
||||
"weekly_return_monday"=>"m",
|
||||
"yearly_day_of_week"=>"1",
|
||||
"yearly_every_x_day"=>"8",
|
||||
"yearly_every_xth_day"=>"1",
|
||||
"yearly_month_of_year2"=>"8",
|
||||
"yearly_month_of_year"=>"6",
|
||||
"yearly_selector"=>"yearly_every_x_day"
|
||||
},
|
||||
"tag_list"=>"one, two, three, four"
|
||||
|
||||
assert_equal "new recurring pattern", assigns['recurring_todo'].description
|
||||
assert_equal "2013-01-02 00:00:00 +0000", assigns['recurring_todo'].start_from.to_s
|
||||
todo = assigns['recurring_todo'].todos.first
|
||||
assert_equal "2013-01-02 00:00:00 +0000", todo.show_from.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def test_find_and_inactivate
|
||||
login_as(:admin_user)
|
||||
|
||||
|
|
|
|||
|
|
@ -691,7 +691,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
recurring_todo_1 = RecurringTodo.find(1)
|
||||
#set_user_to_current_time_zone(recurring_todo_1.user)
|
||||
todo_1 = Todo.where(:recurring_todo_id => 1).first
|
||||
today = Time.zone.now.at_midnight
|
||||
today = Time.zone.now.at_midnight - 1.day
|
||||
|
||||
# change recurrence pattern to monthly and set show_from to today
|
||||
recurring_todo_1.target = 'show_from_date'
|
||||
|
|
@ -730,7 +730,7 @@ class TodosControllerTest < ActionController::TestCase
|
|||
assert !new_todo.show_from.nil?
|
||||
|
||||
# do not use today here. It somehow gets messed up with the timezone calculation.
|
||||
next_month = (Time.zone.now + 1.month).at_midnight
|
||||
next_month = (Time.zone.now - 1.day + 1.month).at_midnight
|
||||
|
||||
assert_equal next_month.utc.to_date.to_s(:db), new_todo.show_from.utc.to_date.to_s(:db)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -175,6 +175,9 @@ class RecurringTodoTest < ActiveSupport::TestCase
|
|||
assert_equal @sunday, due_date # june 8th
|
||||
|
||||
due_date = @monthly.get_due_date(@sunday) # june 8th
|
||||
assert_equal Time.zone.local(2008,6,8), due_date # june 8th
|
||||
|
||||
due_date = @monthly.get_due_date(@monday) # june 9th
|
||||
assert_equal Time.zone.local(2008,8,8), due_date # aug 8th
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue