diff --git a/app/controllers/recurring_todos_controller.rb b/app/controllers/recurring_todos_controller.rb index 0dd786f8..854b20b4 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| @@ -277,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 diff --git a/app/views/contexts/show.html.erb b/app/views/contexts/show.html.erb index c1f5244a..013b883e 100644 --- a/app/views/contexts/show.html.erb +++ b/app/views/contexts/show.html.erb @@ -5,14 +5,13 @@ suffix_completed = t('contexts.last_completed_in_context', :number=>prefs.show_number_completed) deferred_pending_options = {:append_descriptor => nil, :parent_container_type => 'context'} done_todo_options = {:append_descriptor => suffix_completed, :suppress_context => true, :parent_container_type => 'context'} - show_empty_containers = (@group_view_by == 'context') -%> <% cache ["not_done_context", @not_done_todos.empty?] do -%> <%= render partial: "todos/empty_message_container", locals: {:show => @not_done_todos.empty?, :container_name => "not_done"} %> <% end -%> -<%= 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' cache [@last_updated_todo_without_project, @context, "todos_without_project"] do -%> @@ -28,4 +27,4 @@ <% # use the first completed todo (which is the last one to be completed) as cache invariant cache [@context, @done.first, "context_completed"] do -%> <%= show_done_todos(@done, done_todo_options) unless @done.nil? %> -<% end -%> \ No newline at end of file +<% end -%> 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 ############