mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +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
|
|
@ -9,12 +9,12 @@ require "redcloth"
|
||||||
require 'date'
|
require 'date'
|
||||||
require 'time'
|
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
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
|
|
@ -160,7 +160,34 @@ class ApplicationController < ActionController::Base
|
||||||
response.content_type = 'text/html'
|
response.content_type = 'text/html'
|
||||||
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
|
||||||
|
|
@ -192,7 +219,7 @@ class ApplicationController < ActionController::Base
|
||||||
def openid_enabled?
|
def openid_enabled?
|
||||||
self.class.openid_enabled?
|
self.class.openid_enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def parse_date_per_user_prefs( s )
|
def parse_date_per_user_prefs( s )
|
||||||
|
|
@ -231,29 +258,5 @@ class ApplicationController < ActionController::Base
|
||||||
def set_time_zone
|
def set_time_zone
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -1,113 +1,113 @@
|
||||||
module AuthenticatedTestHelper
|
module AuthenticatedTestHelper
|
||||||
# Sets the current user in the session from the user fixtures.
|
# Sets the current user in the session from the user fixtures.
|
||||||
def login_as(user)
|
def login_as(user)
|
||||||
@request.session['user_id'] = user ? users(user).id : nil
|
@request.session['user_id'] = user ? users(user).id : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_type(type)
|
def content_type(type)
|
||||||
@request.env['Content-Type'] = type
|
@request.env['Content-Type'] = type
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept(accept)
|
def accept(accept)
|
||||||
@request.env["HTTP_ACCEPT"] = accept
|
@request.env["HTTP_ACCEPT"] = accept
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize_as(user)
|
def authorize_as(user)
|
||||||
if user
|
if user
|
||||||
@request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}:test")}"
|
@request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}:test")}"
|
||||||
accept 'application/xml'
|
accept 'application/xml'
|
||||||
content_type 'application/xml'
|
content_type 'application/xml'
|
||||||
else
|
else
|
||||||
@request.env["HTTP_AUTHORIZATION"] = nil
|
@request.env["HTTP_AUTHORIZATION"] = nil
|
||||||
accept nil
|
accept nil
|
||||||
content_type nil
|
content_type nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# http://project.ioni.st/post/217#post-217
|
# http://project.ioni.st/post/217#post-217
|
||||||
#
|
#
|
||||||
# def test_new_publication
|
# def test_new_publication
|
||||||
# assert_difference(Publication, :count) do
|
# assert_difference(Publication, :count) do
|
||||||
# post :create, :publication => {...}
|
# post :create, :publication => {...}
|
||||||
# # ...
|
# # ...
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def assert_difference(object, method = nil, difference = 1)
|
def assert_difference(object, method = nil, difference = 1)
|
||||||
initial_value = object.send(method)
|
initial_value = object.send(method)
|
||||||
yield
|
yield
|
||||||
assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
|
assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_no_difference(object, method, &block)
|
def assert_no_difference(object, method, &block)
|
||||||
assert_difference object, method, 0, &block
|
assert_difference object, method, 0, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
# Assert the block redirects to the login
|
# Assert the block redirects to the login
|
||||||
#
|
#
|
||||||
# assert_requires_login(:bob) { |c| c.get :edit, :id => 1 }
|
# assert_requires_login(:bob) { |c| c.get :edit, :id => 1 }
|
||||||
#
|
#
|
||||||
def assert_requires_login(login = nil)
|
def assert_requires_login(login = nil)
|
||||||
yield HttpLoginProxy.new(self, login)
|
yield HttpLoginProxy.new(self, login)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_http_authentication_required(login = nil)
|
def assert_http_authentication_required(login = nil)
|
||||||
yield XmlLoginProxy.new(self, login)
|
yield XmlLoginProxy.new(self, login)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset!(*instance_vars)
|
def reset!(*instance_vars)
|
||||||
instance_vars = [:controller, :request, :response] unless instance_vars.any?
|
instance_vars = [:controller, :request, :response] unless instance_vars.any?
|
||||||
instance_vars.collect! { |v| "@#{v}".to_sym }
|
instance_vars.collect! { |v| "@#{v}".to_sym }
|
||||||
instance_vars.each do |var|
|
instance_vars.each do |var|
|
||||||
instance_variable_set(var, instance_variable_get(var).class.new)
|
instance_variable_set(var, instance_variable_get(var).class.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class BaseLoginProxy
|
class BaseLoginProxy
|
||||||
attr_reader :controller
|
attr_reader :controller
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
def initialize(controller, login)
|
def initialize(controller, login)
|
||||||
@controller = controller
|
@controller = controller
|
||||||
@login = login
|
@login = login
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def authenticated
|
def authenticated
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method, *args)
|
def method_missing(method, *args)
|
||||||
@controller.reset!
|
@controller.reset!
|
||||||
authenticate
|
authenticate
|
||||||
@controller.send(method, *args)
|
@controller.send(method, *args)
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class HttpLoginProxy < BaseLoginProxy
|
class HttpLoginProxy < BaseLoginProxy
|
||||||
protected
|
protected
|
||||||
def authenticate
|
def authenticate
|
||||||
@controller.login_as @login if @login
|
@controller.login_as @login if @login
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
@controller.assert_redirected_to :controller => 'account', :action => 'login'
|
@controller.assert_redirected_to :controller => 'account', :action => 'login'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class XmlLoginProxy < BaseLoginProxy
|
class XmlLoginProxy < BaseLoginProxy
|
||||||
protected
|
protected
|
||||||
def authenticate
|
def authenticate
|
||||||
@controller.accept 'application/xml'
|
@controller.accept 'application/xml'
|
||||||
@controller.authorize_as @login if @login
|
@controller.authorize_as @login if @login
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
@controller.assert_response 401
|
@controller.assert_response 401
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -18,5 +18,5 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
||||||
xhr :post, :destroy, :id => 1, :_source_view => 'todo'
|
xhr :post, :destroy, :id => 1, :_source_view => 'todo'
|
||||||
assert_rjs :page, "recurring_todo_1", :remove
|
assert_rjs :page, "recurring_todo_1", :remove
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -174,12 +174,14 @@ class RecurringTodoTest < Test::Rails::TestCase
|
||||||
def test_yearly_pattern
|
def test_yearly_pattern
|
||||||
# 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
|
||||||
|
|
@ -197,7 +199,7 @@ class RecurringTodoTest < Test::Rails::TestCase
|
||||||
due_date = @yearly.get_due_date(Time.utc(2008,6,12)) # june 7th
|
due_date = @yearly.get_due_date(Time.utc(2008,6,12)) # june 7th
|
||||||
assert_equal Time.utc(2009,6,10), due_date # june 10th
|
assert_equal Time.utc(2009,6,10), due_date # june 10th
|
||||||
|
|
||||||
# test handling of nil
|
# test handling of nil
|
||||||
due_date1 = @yearly.get_due_date(nil)
|
due_date1 = @yearly.get_due_date(nil)
|
||||||
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
|
due_date2 = @yearly.get_due_date(Time.now.utc + 1.day)
|
||||||
assert_equal due_date1, due_date2
|
assert_equal due_date1, due_date2
|
||||||
|
|
@ -207,7 +209,7 @@ class RecurringTodoTest < Test::Rails::TestCase
|
||||||
due_date = @yearly.get_due_date(nil)
|
due_date = @yearly.get_due_date(nil)
|
||||||
assert_equal due_date.year, this_year+2
|
assert_equal due_date.year, this_year+2
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_toggle_completion
|
def test_toggle_completion
|
||||||
t = @yearly
|
t = @yearly
|
||||||
assert_equal :active, t.current_state
|
assert_equal :active, t.current_state
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue