From 0b38f3c43c9f38b44807228801e48a04bb26bf7e Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 5 Sep 2013 17:14:01 +0200 Subject: [PATCH 1/4] clean up a rec todos test --- test/controllers/todos_controller_test.rb | 39 ++++++++++++----------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index 6b44df50..3e6b3e0c 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -718,7 +718,6 @@ class TodosControllerTest < ActionController::TestCase # link todo_1 and recurring_todo_1 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 - 1.day @@ -767,33 +766,37 @@ class TodosControllerTest < ActionController::TestCase def test_check_for_next_todo login_as :admin_user - recurring_todo_1 = RecurringTodo.find(5) - @todo = Todo.where(:recurring_todo_id => 1).first - assert @todo.from_recurring_todo? - # rewire @todo to yearly recurring todo - @todo.recurring_todo_id = 5 + tomorrow = Time.zone.now + 1.day - # make todo due tomorrow and change recurring date also to tomorrow - @todo.due = Time.zone.now + 1.day - @todo.save - recurring_todo_1.every_other1 = @todo.due.day - recurring_todo_1.every_other2 = @todo.due.month + # Given a repeat pattern with recurring date set to tomorrow + recurring_todo_1 = RecurringTodo.find(5) + recurring_todo_1.every_other1 = tomorrow.day + recurring_todo_1.every_other2 = tomorrow.month recurring_todo_1.save - # mark todo complete - xhr :post, :toggle_check, :id => @todo.id, :_source_view => 'todo' - @todo = Todo.find(@todo.id) #reload does not seem to work anymore - assert @todo.completed? + # Given a recurring todo (todo) that belongs to the repeat pattern (recurring_todo_1) and is due tomorrow + todo = Todo.where(:recurring_todo_id => 1).first + assert todo.from_recurring_todo? + todo.recurring_todo_id = 5 # rewire todo to the repeat pattern above + todo.due = tomorrow + todo.save! - # check that there is no active todo + # When I mark the todo complete + xhr :post, :toggle_check, :id => todo.id, :_source_view => 'todo' + todo = Todo.find(todo.id) #reload does not seem to work here + assert todo.completed? + + # Then there should not be an active todo beloning to the repeat pattern next_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'active').first assert next_todo.nil? - # check for new deferred todo + # Then there should be one new deferred todo next_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'deferred').first assert !next_todo.nil? + assert !next_todo.show_from.nil? + # check that the due date of the new todo is later than tomorrow - assert next_todo.due > @todo.due + assert next_todo.due > todo.due end ############ From 7e59b455f2e52bc8c32aef316a544768ffc85cf8 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 5 Sep 2013 17:22:15 +0200 Subject: [PATCH 2/4] fix empty message in context view and handle removing last active todo from context correctly --- app/views/contexts/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/contexts/show.html.erb b/app/views/contexts/show.html.erb index fe44d124..86b653c6 100644 --- a/app/views/contexts/show.html.erb +++ b/app/views/contexts/show.html.erb @@ -6,9 +6,9 @@ -%>
- <%= empty_message_holder("not_done_project", @not_done_todos.empty?) %> + <%= empty_message_holder("not_done_context", @not_done_todos.empty?) %> - <%= show_grouped_todos({:collapsible => false, :show_empty_containers => show_empty_containers, :parent_container_type => 'context'}) %> + <%= show_grouped_todos({:collapsible => false, :show_empty_containers => false, :parent_container_type => 'context'}) %> <% if @group_view_by == 'project' -%> <%= show_todos_without_project(@todos_without_project, {:collapsible => false, :parent_container_type => 'context', :title_param => @context.name}) -%> From 3ef55f3b1702421c15c552df91a8bd694c3e53b4 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 5 Sep 2013 20:09:39 +0200 Subject: [PATCH 3/4] Hopfully fix #1434 by updating selectors first. Same fix as #1431 but now for update Conflicts: app/controllers/recurring_todos_controller.rb --- app/controllers/recurring_todos_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/recurring_todos_controller.rb b/app/controllers/recurring_todos_controller.rb index 0dd786f8..31f158d8 100644 --- a/app/controllers/recurring_todos_controller.rb +++ b/app/controllers/recurring_todos_controller.rb @@ -89,6 +89,15 @@ class RecurringTodosController < ApplicationController params["recurring_todo"]["weekly_return_"+day]=' ' if params["recurring_todo"]["weekly_return_"+day].nil? end + selector_attributes = { + 'recurring_period' => recurring_todo_params['recurring_period'], + 'daily_selector' => recurring_todo_params['daily_selector'], + 'monthly_selector' => recurring_todo_params['monthly_selector'], + 'yearly_selector' => recurring_todo_params['yearly_selector'] + } + + @recurring_todo.assign_attributes(:recurring_period => recurring_todo_params[:recurring_period]) + @recurring_todo.assign_attributes(selector_attributes) @saved = @recurring_todo.update_attributes recurring_todo_params respond_to do |format| From 4ca6114b768aed5c89813028178da7ade9b74f5c Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 5 Sep 2013 20:18:14 +0200 Subject: [PATCH 4/4] weekly days were not getting through to the update of a recurring weekly todo --- app/controllers/recurring_todos_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/recurring_todos_controller.rb b/app/controllers/recurring_todos_controller.rb index 31f158d8..854b20b4 100644 --- a/app/controllers/recurring_todos_controller.rb +++ b/app/controllers/recurring_todos_controller.rb @@ -286,7 +286,10 @@ class RecurringTodosController < ApplicationController :monthly_every_xth_day, :recurring_show_days_before, :recurring_show_always, :weekly_every_x_week, :weekly_return_monday, :yearly_day_of_week, :yearly_every_x_day, :yearly_every_xth_day, - :yearly_month_of_year2, :yearly_month_of_year + :yearly_month_of_year2, :yearly_month_of_year, + # derived attribues + :weekly_return_monday, :weekly_return_tuesday, :weekly_return_wednesday, + :weekly_return_thursday, :weekly_return_friday, :weekly_return_saturday, :weekly_return_sunday ) end