mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 15:50:13 +01:00
fix corner case where recurring todo with due in future and show_from in past did not create corresponding todo
you cannot add todos with show_from in the past
This commit is contained in:
parent
223cf93597
commit
065f543a83
4 changed files with 151 additions and 146 deletions
|
|
@ -11,8 +11,8 @@ require 'time'
|
||||||
|
|
||||||
# Commented the following line because of #744. It prevented rake db:migrate to
|
# Commented the following line because of #744. It prevented rake db:migrate to
|
||||||
# run because this tag went looking for the taggings table that did not exist
|
# run because this tag went looking for the taggings table that did not exist
|
||||||
# when you feshly create a new database
|
# when you feshly create a new database Old comment: We need this in development
|
||||||
# Old comment: We need this in development mode, or you get 'method missing' errors
|
# mode, or you get 'method missing' errors
|
||||||
#
|
#
|
||||||
# Tag
|
# Tag
|
||||||
|
|
||||||
|
|
@ -161,6 +161,33 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_todo_from_recurring_todo(rt, date=nil)
|
||||||
|
# create todo and initialize with data from recurring_todo rt
|
||||||
|
todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id})
|
||||||
|
|
||||||
|
# set dates
|
||||||
|
todo.recurring_todo_id = rt.id
|
||||||
|
todo.due = rt.get_due_date(date)
|
||||||
|
# make sure that show_from is not in the past
|
||||||
|
show_from_date = rt.get_show_from_date(date)
|
||||||
|
todo.show_from = show_from_date < Time.now.utc ? nil : show_from_date
|
||||||
|
|
||||||
|
saved = todo.save
|
||||||
|
if saved
|
||||||
|
todo.tag_with(rt.tag_list, current_user)
|
||||||
|
todo.tags.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
# increate number of occurences created from recurring todo
|
||||||
|
rt.inc_occurences
|
||||||
|
|
||||||
|
# mark recurring todo complete if there are no next actions left
|
||||||
|
checkdate = todo.due.nil? ? todo.show_from : todo.due
|
||||||
|
rt.toggle_completion! unless rt.has_next_todo(checkdate)
|
||||||
|
|
||||||
|
return saved ? todo : nil
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def admin_login_required
|
def admin_login_required
|
||||||
|
|
@ -232,28 +259,4 @@ class ApplicationController < ActionController::Base
|
||||||
Time.zone = current_user.prefs.time_zone if logged_in?
|
Time.zone = current_user.prefs.time_zone if logged_in?
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_todo_from_recurring_todo(rt, date=nil)
|
|
||||||
# create todo and initialize with data from recurring_todo rt
|
|
||||||
todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id})
|
|
||||||
|
|
||||||
# set dates
|
|
||||||
todo.due = rt.get_due_date(date)
|
|
||||||
todo.show_from = rt.get_show_from_date(date)
|
|
||||||
todo.recurring_todo_id = rt.id
|
|
||||||
saved = todo.save
|
|
||||||
if saved
|
|
||||||
todo.tag_with(rt.tag_list, current_user)
|
|
||||||
todo.tags.reload
|
|
||||||
end
|
|
||||||
|
|
||||||
# increate number of occurences created from recurring todo
|
|
||||||
rt.inc_occurences
|
|
||||||
|
|
||||||
# mark recurring todo complete if there are no next actions left
|
|
||||||
checkdate = todo.due.nil? ? todo.show_from : todo.due
|
|
||||||
rt.toggle_completion! unless rt.has_next_todo(checkdate)
|
|
||||||
|
|
||||||
return saved ? todo : nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -175,11 +175,13 @@ class RecurringTodoTest < Test::Rails::TestCase
|
||||||
# beginning of same year
|
# beginning of same year
|
||||||
due_date = @yearly.get_due_date(Time.utc(2008,2,10)) # feb 10th
|
due_date = @yearly.get_due_date(Time.utc(2008,2,10)) # feb 10th
|
||||||
assert_equal @sunday, due_date # june 8th
|
assert_equal @sunday, due_date # june 8th
|
||||||
|
|
||||||
# same month, previous date
|
# same month, previous date
|
||||||
due_date = @yearly.get_due_date(@saturday) # june 7th
|
due_date = @yearly.get_due_date(@saturday) # june 7th
|
||||||
show_from_date = @yearly.get_show_from_date(@saturday) # june 7th
|
show_from_date = @yearly.get_show_from_date(@saturday) # june 7th
|
||||||
assert_equal @sunday, due_date # june 8th
|
assert_equal @sunday, due_date # june 8th
|
||||||
assert_equal @sunday-5.days, show_from_date
|
assert_equal @sunday-5.days, show_from_date
|
||||||
|
|
||||||
# same month, day after
|
# same month, day after
|
||||||
due_date = @yearly.get_due_date(@monday) # june 9th
|
due_date = @yearly.get_due_date(@monday) # june 9th
|
||||||
assert_equal Time.utc(2009,6,8), due_date # june 8th next year
|
assert_equal Time.utc(2009,6,8), due_date # june 8th next year
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue