From cec2e535b289d709c66085f54b6e8cf167abf173 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Mon, 16 Mar 2015 00:03:34 +0100 Subject: [PATCH 01/13] fix #1754 --- app/models/dependency.rb | 8 ++++++++ app/models/todo.rb | 9 --------- test/models/todo_test.rb | 7 +++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/models/dependency.rb b/app/models/dependency.rb index e9fd8fcc..22e144b7 100644 --- a/app/models/dependency.rb +++ b/app/models/dependency.rb @@ -5,5 +5,13 @@ class Dependency < ActiveRecord::Base belongs_to :predecessor, :foreign_key => 'predecessor_id', :class_name => 'Todo', :touch => true belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true + validate :check_circular_dependencies + + def check_circular_dependencies + unless predecessor.nil? or successor.nil? + errors.add("Depends on:", "Adding '#{successor.specification}' would create a circular dependency") if successor.is_successor?(predecessor) + end + end + end diff --git a/app/models/todo.rb b/app/models/todo.rb index 88178891..45b0ae81 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -115,7 +115,6 @@ class Todo < ActiveRecord::Base validates_presence_of :show_from, :if => :deferred? validates_presence_of :context validate :check_show_from_in_future - validate :check_circular_dependencies def check_show_from_in_future if show_from_changed? # only check on change of show_from @@ -125,14 +124,6 @@ class Todo < ActiveRecord::Base end end - def check_circular_dependencies - unless @predecessor_array.nil? # Only validate predecessors if they changed - @predecessor_array.each do |todo| - errors.add("Depends on:", "Adding '#{todo.specification}' would create a circular dependency") if is_successor?(todo) - end - end - end - def initialize(*args) super(*args) @predecessor_array = nil # Used for deferred save of predecessors diff --git a/test/models/todo_test.rb b/test/models/todo_test.rb index 4662a283..b79bf26b 100644 --- a/test/models/todo_test.rb +++ b/test/models/todo_test.rb @@ -93,10 +93,9 @@ class TodoTest < ActiveSupport::TestCase assert_equal 1, @not_completed3.successors.count # 1 -> 3 -> 2 -> 1 == circle - @not_completed3.add_predecessor(@not_completed1) - assert !@not_completed3.valid? - error_msg = "Adding ''Call Bill Gates to find out how much he makes per day' <'agenda'; 'Make more money than Billy Gates'>' would create a circular dependency" - assert_equal error_msg, @not_completed3.errors["Depends on:"][0] + assert_raises ActiveRecord::RecordInvalid do + @not_completed3.add_predecessor(@not_completed1) + end end def test_defer_an_existing_todo From 32b48df78f994c0b5018477a8bfdf808a3fcfc3b Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Wed, 25 Mar 2015 10:12:56 +0100 Subject: [PATCH 02/13] catch exception to show error message in GUI as before --- app/controllers/todos_controller.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 5fc14a65..4495abef 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -257,9 +257,13 @@ class TodosController < ApplicationController @todo = current_user.todos.includes(Todo::DEFAULT_INCLUDES).find(params['successor']) @original_state = @todo.state unless @predecessor.completed? - @todo.add_predecessor(@predecessor) - @todo.block! unless @todo.pending? - @saved = @todo.save + begin + @todo.add_predecessor(@predecessor) + @todo.block! unless @todo.pending? + @saved = @todo.save + rescue ActiveRecord::RecordInvalid + @saved = false + end @status_message = t('todos.added_dependency', :dependency => @predecessor.description) @status_message += t('todos.set_to_pending', :task => @todo.description) unless @original_state == 'pending' From 6017637abcf37e11cf5a8203182640ebe18ffb4e Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sun, 22 Mar 2015 00:50:01 +0100 Subject: [PATCH 03/13] do not activate already completed todos, fix #1778 --- app/models/todo.rb | 2 +- test/controllers/todos_controller_test.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/todo.rb b/app/models/todo.rb index 45b0ae81..3f82e217 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -308,7 +308,7 @@ class Todo < ActiveRecord::Base # activate todos that should be activated if the current todo is completed def activate_pending_todos - pending_todos = successors.select {|t| t.uncompleted_predecessors.empty?} + pending_todos = successors.select { |t| t.uncompleted_predecessors.empty? and !t.completed? } pending_todos.each {|t| t.activate! } return pending_todos end diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index fcde26dd..910c6c7f 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -1003,6 +1003,24 @@ class TodosControllerTest < ActionController::TestCase assert t4.predecessors.map(&:id).include?(t3.id) end + + def test_do_not_activate_done_successors + login_as(:admin_user) + predecessor = Todo.find(1) + successor = Todo.find(2) + successor.add_predecessor(predecessor) + + successor.complete! + xhr :post, :toggle_check, :id => predecessor.id, :_source_view => 'todo' + + predecessor.reload + successor.reload + assert !predecessor.active? + assert !successor.active? + assert predecessor.completed? + assert successor.completed? + end + private def create_todo(params={}) From 12ee2ed5e35fb340234171d4fee49db1f2e0c625 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Wed, 25 Mar 2015 10:12:06 +0100 Subject: [PATCH 04/13] typo --- test/models/todo_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/todo_test.rb b/test/models/todo_test.rb index b79bf26b..dcdf1a2d 100644 --- a/test/models/todo_test.rb +++ b/test/models/todo_test.rb @@ -266,7 +266,7 @@ class TodoTest < ActiveSupport::TestCase assert !@not_completed1.starred? end - def test_hidden_todo_remains_hidden_after_getting_unblokked + def test_hidden_todo_remains_hidden_after_getting_unblocked todo = todos(:call_bill) project=todo.project project.hide! From eb1012f1f27490de6ddb6e71e5df36b5d0a6d02b Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sat, 4 Apr 2015 17:36:54 +0200 Subject: [PATCH 05/13] typo --- .../{_update_succesfull.js.erb => _update_successful.js.erb} | 0 app/views/todos/update.js.erb | 2 +- config/locales/en.yml | 4 ++-- config/locales/es.yml | 4 ++-- features/project_edit.feature | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) rename app/views/todos/{_update_succesfull.js.erb => _update_successful.js.erb} (100%) diff --git a/app/views/todos/_update_succesfull.js.erb b/app/views/todos/_update_successful.js.erb similarity index 100% rename from app/views/todos/_update_succesfull.js.erb rename to app/views/todos/_update_successful.js.erb diff --git a/app/views/todos/update.js.erb b/app/views/todos/update.js.erb index 68049d38..15cd7588 100644 --- a/app/views/todos/update.js.erb +++ b/app/views/todos/update.js.erb @@ -1,5 +1,5 @@ <%- object_name = unique_object_name_for("update_todo_#{@todo.id}") -%> var <%=object_name%> = { - <%= render :partial => (@saved ? "update_succesfull" : "update_has_errors"), locals: {object_name: object_name} %> + <%= render :partial => (@saved ? "update_successful" : "update_has_errors"), locals: {object_name: object_name} %> } <%=object_name%>.animate(); \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 023d6b02..33e6aa04 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -542,7 +542,7 @@ en: edit: Edit pending: Pending completed_actions_with: "Completed actions with the tag '%{tag_name}'" - deleted_success: The action was deleted succesfully. + deleted_success: The action was deleted successfully. completed_tasks_title: TRACKS::Completed tasks feed_title_in_project: "in project '%{project}'" clear_due_date: Clear due date @@ -552,7 +552,7 @@ en: show_on_date: Show on %{date} recurrence_period: Recurrence period deferred_actions_with: "Deferred actions with the tag '%{tag_name}'" - recurring_deleted_success: The recurring action was deleted succesfully. + recurring_deleted_success: The recurring action was deleted successfully. confirm_delete: "Are you sure that you want to delete the action '%{description}'?" deferred_tasks_title: TRACKS::Tickler next_actions_title: Tracks - Next Actions diff --git a/config/locales/es.yml b/config/locales/es.yml index 9aa645dc..615fbead 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -761,7 +761,7 @@ es: one: Defer one day other: Defer %{count} days delete: Delete - deleted_success: The action was deleted succesfully. + deleted_success: The action was deleted successfully. delete_action: Delete action delete_recurring_action_confirm: Are you sure that you want to delete the recurring action '%{description}'? @@ -897,7 +897,7 @@ es: recurring_action_deleted: Action was deleted. Because this action is recurring, a new action was added recurring_action_saved: Recurring action saved - recurring_deleted_success: The recurring action was deleted succesfully. + recurring_deleted_success: The recurring action was deleted successfully. recurring_pattern_removed: El patrón de repetición se retira de %{count} recurring_todos: Recurring todos removed_predecessor: Removed %{successor} as dependency from %{predecessor}. diff --git a/features/project_edit.feature b/features/project_edit.feature index 412cb42d..83b09738 100644 --- a/features/project_edit.feature +++ b/features/project_edit.feature @@ -19,8 +19,8 @@ Feature: Edit a project @javascript Scenario: I can describe the project using markup When I go to the "manage me" project - And I edit the project description to "_successfull outcome_: project is *done*" - Then I should see the italic text "successfull outcome" in the project description + And I edit the project description to "_successful outcome_: project is *done*" + Then I should see the italic text "successful outcome" in the project description And I should see the bold text "done" in the project description @javascript From 502543f348e177d5b56eb9c38868a55c2925a947 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sat, 4 Apr 2015 17:38:51 +0200 Subject: [PATCH 06/13] typo --- app/controllers/todos_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 4495abef..e3cb1ca6 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -413,7 +413,7 @@ class TodosController < ApplicationController @todo = current_user.todos.find(params['id']) @original_item = current_user.todos.build(@todo.attributes) # create a (unsaved) copy of the original todo - cache_attributes_from_before_update # TODO: remove in favor of @orininal_item + cache_attributes_from_before_update # TODO: remove in favor of @original_item update_tags update_project From f3c36e6e046071c90ea6ebf8e61e727d781e4237 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Mon, 6 Apr 2015 23:59:52 +0200 Subject: [PATCH 07/13] Fix typo --- features/tickler.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/tickler.feature b/features/tickler.feature index 6efafd25..898020d9 100644 --- a/features/tickler.feature +++ b/features/tickler.feature @@ -42,7 +42,7 @@ Feature: Manage deferred todos | project | @javascript - Scenario Outline: Editing the container of a todo moves it to the new contaier + Scenario Outline: Editing the container of a todo moves it to the new container Given I have a context called "A" And I have a context called "B" And I have a project called "pA" From 006c135a6450496f6dbfca99f81008e6380215b0 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 13 Apr 2015 15:33:22 +0200 Subject: [PATCH 08/13] do not compare at_midnight in different timezones. Use localtime to make sure both dates are in the same timezone --- app/controllers/todos_controller.rb | 2 +- .../recurring_todos/monthly_repeat_pattern.rb | 2 +- test/controllers/todos_controller_test.rb | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index e3cb1ca6..60a7d5c1 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -1055,7 +1055,7 @@ end if recurring_todo.todos.active.count == 0 # check for next todo either from the due date or the show_from date - date_to_check = todo.due.nil? ? todo.show_from : todo.due + date_to_check = todo.due.nil? ? todo.show_from.localtime : todo.due.localtime # if both due and show_from are nil, check for a next todo from now date_to_check = Time.zone.now if date_to_check.nil? diff --git a/app/models/recurring_todos/monthly_repeat_pattern.rb b/app/models/recurring_todos/monthly_repeat_pattern.rb index c602edb8..6167606a 100644 --- a/app/models/recurring_todos/monthly_repeat_pattern.rb +++ b/app/models/recurring_todos/monthly_repeat_pattern.rb @@ -93,7 +93,7 @@ module RecurringTodos # TODO: recheck if future rails versions have this problem too start = Time.utc(start.year, start.month, start.day)+n.months end - Time.zone.local(start.year, start.month, every_x_day) + Time.zone.local(start.year, start.month, every_x_day).localtime.at_midnight end def find_relative_day_of_month(start, n) diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index 910c6c7f..ed185ba9 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -120,7 +120,7 @@ class TodosControllerTest < ActionController::TestCase assert_response :success assert_equal 3, @tagged end - + def test_find_tagged_with_terms_separated_with_dot login_as :admin_user create_todo(description: "test dotted tag", tag_list: "first.last, second") @@ -408,7 +408,7 @@ class TodosControllerTest < ActionController::TestCase ####### # defer - ####### + ####### def test_update_clearing_show_from_makes_todo_active t = Todo.find(1) @@ -437,7 +437,7 @@ class TodosControllerTest < ActionController::TestCase # given a todo in the tickler that should be activated travel_to 2.weeks.ago do create_todo( - description: "tickler", + description: "tickler", show_from: 1.week.from_now. in_time_zone(users(:admin_user).prefs.time_zone). strftime("#{users(:admin_user).prefs.date_format}")) @@ -740,14 +740,14 @@ class TodosControllerTest < ActionController::TestCase # locate the new todo in tickler new_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'deferred').first - assert !new_todo.nil?, "the todo should be in the tickler" + refute new_todo.nil?, "the todo should be in the tickler" assert_equal "Call Bill Gates every day", new_todo.description assert_not_equal todo_1.id, new_todo.id, "check that the new todo is not the same as todo_1" - assert !new_todo.show_from.nil?, "check that the new_todo is in the tickler to show next month" + refute new_todo.show_from.nil?, "check that the new_todo is in the tickler to show next month" # 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 = (today + 1.month).localtime.at_midnight assert_equal next_month.utc.to_date.to_s(:db), new_todo.show_from.utc.to_date.to_s(:db) end @@ -1024,13 +1024,13 @@ class TodosControllerTest < ActionController::TestCase private def create_todo(params={}) - defaults = { source_view: 'todo', - context_name: "library", project_name: "Build a working time machine", + defaults = { source_view: 'todo', + context_name: "library", project_name: "Build a working time machine", notes: "note", description: "a new todo", due: nil, tag_list: "a,b,c"} params=params.reverse_merge(defaults) - put :create, _source_view: params[:_source_view], + put :create, _source_view: params[:_source_view], context_name: params[:context_name], project_name: params[:project_name], tag_list: params[:tag_list], todo: {notes: params[:notes], description: params[:description], due: params[:due], show_from: params[:show_from]} end From c7c923a317dd7f1cf5f1518c7ce072ec505af025 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 13 Apr 2015 15:42:35 +0200 Subject: [PATCH 09/13] discard time in these tests since they are irrelevant here --- .../abstract_repeat_pattern_test.rb | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/models/recurring_todos/abstract_repeat_pattern_test.rb b/test/models/recurring_todos/abstract_repeat_pattern_test.rb index fcb3e025..d4d0adc8 100644 --- a/test/models/recurring_todos/abstract_repeat_pattern_test.rb +++ b/test/models/recurring_todos/abstract_repeat_pattern_test.rb @@ -8,7 +8,7 @@ module RecurringTodos def setup super @admin = users(:admin_user) - end + end def test_pattern_builds_from_existing_recurring_todo rt = @admin.recurring_todos.first @@ -121,9 +121,9 @@ module RecurringTodos def test_determine_start travel_to Time.zone.local(2013,1,1) do rt = create_recurring_todo - assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil).to_s(:db), "no previous date, use today" - assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil, 1.day).to_s(:db), "no previous date, use today without offset" - assert_equal "2013-01-02 00:00:00", rt.send(:determine_start, Time.zone.now, 1.day).to_s(:db), "use previous date and offset" + assert_equal "2013-01-01", rt.send(:determine_start, nil).to_date.to_s(:db), "no previous date, use today" + assert_equal "2013-01-01", rt.send(:determine_start, nil, 1.day).to_date.to_s(:db), "no previous date, use today without offset" + assert_equal "2013-01-02", rt.send(:determine_start, Time.zone.now, 1.day).to_date.to_s(:db), "use previous date and offset" end end @@ -131,14 +131,14 @@ module RecurringTodos rt = create_recurring_todo # march 2014 has 5 saturdays, the last will return the 5th - assert_equal "2014-03-01 00:00:00", rt.send(:get_xth_day_of_month, 1, 6, 3, 2014).to_s(:db) - assert_equal "2014-03-22 00:00:00", rt.send(:get_xth_day_of_month, 4, 6, 3, 2014).to_s(:db) - assert_equal "2014-03-29 00:00:00", rt.send(:get_xth_day_of_month, 5, 6, 3, 2014).to_s(:db) + assert_equal "2014-03-01", rt.send(:get_xth_day_of_month, 1, 6, 3, 2014).to_date.to_s(:db) + assert_equal "2014-03-22", rt.send(:get_xth_day_of_month, 4, 6, 3, 2014).to_date.to_s(:db) + assert_equal "2014-03-29", rt.send(:get_xth_day_of_month, 5, 6, 3, 2014).to_date.to_s(:db) # march 2014 has 4 fridays, the last will return the 4th - assert_equal "2014-03-07 00:00:00", rt.send(:get_xth_day_of_month, 1, 5, 3, 2014).to_s(:db) - assert_equal "2014-03-28 00:00:00", rt.send(:get_xth_day_of_month, 4, 5, 3, 2014).to_s(:db) - assert_equal "2014-03-28 00:00:00", rt.send(:get_xth_day_of_month, 5, 5, 3, 2014).to_s(:db) + assert_equal "2014-03-07", rt.send(:get_xth_day_of_month, 1, 5, 3, 2014).to_date.to_s(:db) + assert_equal "2014-03-28", rt.send(:get_xth_day_of_month, 4, 5, 3, 2014).to_date.to_s(:db) + assert_equal "2014-03-28", rt.send(:get_xth_day_of_month, 5, 5, 3, 2014).to_date.to_s(:db) assert_raise(RuntimeError, "should check on valid weekdays"){ rt.send(:get_xth_day_of_month, 5, 9, 3, 2014) } assert_raise(RuntimeError, "should check on valid count x"){ rt.send(:get_xth_day_of_month, 6, 5, 3, 2014) } From c129b8a06fe53eb06aaf3b37770b954487383500 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 13 Apr 2015 15:48:20 +0200 Subject: [PATCH 10/13] fix a few more timezone issues with the use of localtime --- .../recurring_todos_controller_test.rb | 16 ++--- test/controllers/stats_controller_test.rb | 68 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/test/controllers/recurring_todos_controller_test.rb b/test/controllers/recurring_todos_controller_test.rb index c9c2bce7..cccadb24 100644 --- a/test/controllers/recurring_todos_controller_test.rb +++ b/test/controllers/recurring_todos_controller_test.rb @@ -184,7 +184,7 @@ class RecurringTodosControllerTest < ActionController::TestCase # mark as active xhr :post, :toggle_check, :id=>1, :_source_view=>"" - + recurring_todo_1 = RecurringTodo.find(1) # reload seems to not work assert recurring_todo_1.active?, "recurring todo should be active but is #{recurring_todo_1.aasm.current_state}" @@ -260,7 +260,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "recurring_show_days_before"=>"0", "recurring_target"=>"due_date", "recurring_show_always" => "1", - "start_from"=>"1/10/2012", + "start_from"=>"1/10/2012", "weekly_every_x_week"=>"1", "weekly_return_monday"=>"w", "yearly_day_of_week"=>"0", @@ -379,9 +379,9 @@ class RecurringTodosControllerTest < ActionController::TestCase "tag_list"=>"one, two, three, four", format: :js 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 + assert_equal "2013-01-02", assigns['recurring_todo'].start_from.localtime.to_date.to_s todo = assigns['recurring_todo'].todos.first - assert_equal "2013-01-02 00:00:00 +0000", todo.show_from.to_s + assert_equal "2013-01-02", todo.show_from.localtime.to_date.to_s end end @@ -419,9 +419,9 @@ class RecurringTodosControllerTest < ActionController::TestCase login_as(:admin_user) rt = recurring_todos(:call_bill_gates_every_day) - put :update, - "recurring_todo" => { - "description" => "changed", + put :update, + "recurring_todo" => { + "description" => "changed", "daily_selector" => "daily_every_x_day", "daily_every_x_days" => "2", "ends_on" => "no_end_date", @@ -433,7 +433,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "recurring_todo_edit_start_from" => "2/1/2013", "end_date" => nil, "ends_on" => "no_end_date", - "id" => "#{rt.id}", + "id" => "#{rt.id}", "context_name" => "library", format: :js diff --git a/test/controllers/stats_controller_test.rb b/test/controllers/stats_controller_test.rb index 2c7e3485..d2140348 100644 --- a/test/controllers/stats_controller_test.rb +++ b/test/controllers/stats_controller_test.rb @@ -49,7 +49,7 @@ class StatsControllerTest < ActionController::TestCase totals = assigns['stats'].totals assert_equal 4, totals.tags assert_equal 2, totals.unique_tags - assert_equal 2.week.ago.utc.at_midnight, totals.first_action_at.utc.at_midnight + assert_equal 2.weeks.ago.localtime.at_midnight, totals.first_action_at.localtime.at_midnight end def test_downdrill @@ -128,15 +128,15 @@ class StatsControllerTest < ActionController::TestCase # And they should be averaged over three months assert_equal 2/3.0, assigns['actions_done_avg_last12months_array'][1], "fourth month should be excluded" assert_equal 2/3.0, assigns['actions_done_avg_last12months_array'][2], "fourth month should be included" - + assert_equal (3)/3.0, assigns['actions_created_avg_last12months_array'][1], "one every month" assert_equal (4)/3.0, assigns['actions_created_avg_last12months_array'][2], "two in fourth month" - + # And the current month should be interpolated fraction = Time.zone.now.day.to_f / Time.zone.now.end_of_month.day.to_f assert_equal (2*(1/fraction)+2)/3.0, assigns['interpolated_actions_created_this_month'], "two this month and one in the last two months" assert_equal (2)/3.0, assigns['interpolated_actions_done_this_month'], "none this month and one two the last two months" - + # And totals should be calculated assert_equal 2, assigns['max'], "max of created or completed todos in one month" end @@ -168,7 +168,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -176,7 +176,7 @@ class StatsControllerTest < ActionController::TestCase assert_response :success # only tests relevant differences with actions_done_last_12months_data - + assert_equal 31, assigns['actions_done_last30days_array'].size, "30 complete days plus 1 for the current day" assert_equal 2, assigns['max'], "two actions created on one day is max" end @@ -185,31 +185,31 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data get :actions_done_lastyears_data assert_response :success - + # only tests difference with actions_done_last_12months_data - + # And the last two months are corrected assert_equal 2/3.0, assigns['actions_done_avg_last_months_array'][23] assert_equal 2/3.0, assigns['actions_done_avg_last_months_array'][24] end - + def test_actions_completion_time_data login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats - + # When I get the chart data get :actions_completion_time_data assert_response :success - + # do not test stuff already implicitly tested in other tests assert_equal 104, assigns['max_weeks'], "two years is 104 weeks (for completed_at)" assert_equal 3, assigns['max_actions'], "3 completed within one week" @@ -222,13 +222,13 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats - + # When I get the chart data get :actions_running_time_data assert_response :success - + # do not test stuff already implicitly tested in other tests assert_equal 17, assigns['max_weeks'], "there are actions in the first 17 weeks of this year" assert_equal 2, assigns['max_actions'], "2 actions running long together" @@ -241,13 +241,13 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats - + # When I get the chart data get :actions_open_per_week_data assert_response :success - + # do not test stuff already implicitly tested in other tests assert_equal 17, assigns['max_weeks'], "there are actions in the first 17 weeks of this year" assert_equal 4, assigns['max_actions'], "4 actions running together" @@ -258,12 +258,12 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # Given todo1 is deferred (i.e. not visible) @todo_today1.show_from = Time.zone.now + 1.week @todo_today1.save - + # When I get the chart data get :actions_visible_running_time_data assert_response :success @@ -281,7 +281,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -311,7 +311,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -335,12 +335,12 @@ class StatsControllerTest < ActionController::TestCase assert_equal 14, assigns['data'].values[9], "pie slices limited to max 10; last pie contains sum of rest (in percentage)" assert_equal "(others)", assigns['data'].labels[9], "pie slices limited to max 10; last slice contains label for others" end - + def test_actions_day_of_week_all_data login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -358,7 +358,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -376,7 +376,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -389,12 +389,12 @@ class StatsControllerTest < ActionController::TestCase assert_not_nil assigns['actions_creation_hour_array'] assert_not_nil assigns['actions_completion_hour_array'] end - + def test_show_selected_actions_from_chart_avrt login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -409,7 +409,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -424,7 +424,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -439,7 +439,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -451,7 +451,7 @@ class StatsControllerTest < ActionController::TestCase end private - + def given_todos_for_stats # Given two todos created today @todo_today1 = @current_user.todos.create!(:description => "created today1", :context => contexts(:office)) @@ -491,7 +491,7 @@ class StatsControllerTest < ActionController::TestCase def difference_in_days(date1, date2) return ((date1.at_midnight-date2.at_midnight)/(60*60*24)).to_i end - + # assumes date1 > date2 def difference_in_weeks(date1, date2) return difference_in_days(date1, date2) / 7 From 700305055f1bc1260ffd9b9fe2057fe4814b68a9 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Tue, 7 Apr 2015 00:30:10 +0200 Subject: [PATCH 11/13] Add step definitions to create deferred actions --- features/step_definitions/todo_create_steps.rb | 6 +++++- features/step_definitions/web_steps.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/features/step_definitions/todo_create_steps.rb b/features/step_definitions/todo_create_steps.rb index 9eaf5c38..db121238 100644 --- a/features/step_definitions/todo_create_steps.rb +++ b/features/step_definitions/todo_create_steps.rb @@ -100,9 +100,13 @@ Given /^I have ([0-9]+) deferred todos$/ do |count| end Given /^I have a deferred todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name| + step "I have a deferred todo \"#{description}\" in the context \"#{context_name}\" deferred by 7 days" +end + +Given /^I have a (?:deferred )todo "([^"]*)" in the context "([^"]*)" deferred by (\d+) day(?:s)?$/ do |description, context_name, deferred_by_days| context = @current_user.contexts.where(:name => context_name).first_or_create todo = @current_user.todos.create!(:context_id => context.id, :description => description) - todo.show_from = UserTime.new(@current_user).time + 1.week + todo.show_from = UserTime.new(@current_user).time + deferred_by_days.to_i.day todo.save! end diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index f3e8a091..e55029a3 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -110,6 +110,12 @@ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| end end +Then /^(?:|I )should see "([^"]*)" before "([^"]*)"$/ do |earlier_content, later_content| + expect(page).to have_content(earlier_content) + expect(page).to have_content(later_content) + page.body.index(earlier_content).should < page.body.index(later_content) +end + Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| regexp = Regexp.new(regexp) with_scope(selector) do From aa14a8e8020c1f526af547ef822d26265e822660 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Sun, 12 Apr 2015 23:22:04 +0200 Subject: [PATCH 12/13] Sort by 'show_from' in tickler --- app/controllers/todos_controller.rb | 2 +- features/tickler.feature | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 60a7d5c1..0bbc8a50 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -558,7 +558,7 @@ class TodosController < ApplicationController includes = params[:format]=='xml' ? [:context, :project] : Todo::DEFAULT_INCLUDES - @not_done_todos = current_user.todos.deferred.includes(includes) + current_user.todos.pending.includes(includes) + @not_done_todos = current_user.todos.deferred.includes(includes).reorder('show_from') + current_user.todos.pending.includes(includes) @todos_without_project = @not_done_todos.select{|t|t.project.nil?} @down_count = @count = @not_done_todos.size diff --git a/features/tickler.feature b/features/tickler.feature index 898020d9..c8512781 100644 --- a/features/tickler.feature +++ b/features/tickler.feature @@ -98,3 +98,12 @@ Feature: Manage deferred todos | grouping | | context | | project | + + Scenario: Opening the tickler page shows the deferred todos in order + Given I have a deferred todo "show tomorrow" in the context "Context B" deferred by 1 day + And I have a deferred todo "show in a year" in the context "Context B" deferred by 365 days + And I have a deferred todo "show in a week" in the context "Context B" deferred by 7 days + When I go to the tickler page + Then I should see "show tomorrow" before "show in a week" + And I should see "show tomorrow" before "show in a year" + And I should see "show in a week" before "show in a year" From 556c68c2e61ca0e504a33213435fcb6fdbeece80 Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Tue, 14 Apr 2015 22:26:07 -0400 Subject: [PATCH 13/13] Revert breaking commits This reverts the following commits: c129b8a06fe53eb06aaf3b37770b954487383500 c7c923a317dd7f1cf5f1518c7ce072ec505af025 006c135a6450496f6dbfca99f81008e6380215b0 --- app/controllers/todos_controller.rb | 2 +- .../recurring_todos/monthly_repeat_pattern.rb | 2 +- .../recurring_todos_controller_test.rb | 16 ++--- test/controllers/stats_controller_test.rb | 68 +++++++++---------- test/controllers/todos_controller_test.rb | 18 ++--- .../abstract_repeat_pattern_test.rb | 20 +++--- 6 files changed, 63 insertions(+), 63 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 0bbc8a50..f54669f6 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -1055,7 +1055,7 @@ end if recurring_todo.todos.active.count == 0 # check for next todo either from the due date or the show_from date - date_to_check = todo.due.nil? ? todo.show_from.localtime : todo.due.localtime + date_to_check = todo.due.nil? ? todo.show_from : todo.due # if both due and show_from are nil, check for a next todo from now date_to_check = Time.zone.now if date_to_check.nil? diff --git a/app/models/recurring_todos/monthly_repeat_pattern.rb b/app/models/recurring_todos/monthly_repeat_pattern.rb index 6167606a..c602edb8 100644 --- a/app/models/recurring_todos/monthly_repeat_pattern.rb +++ b/app/models/recurring_todos/monthly_repeat_pattern.rb @@ -93,7 +93,7 @@ module RecurringTodos # TODO: recheck if future rails versions have this problem too start = Time.utc(start.year, start.month, start.day)+n.months end - Time.zone.local(start.year, start.month, every_x_day).localtime.at_midnight + Time.zone.local(start.year, start.month, every_x_day) end def find_relative_day_of_month(start, n) diff --git a/test/controllers/recurring_todos_controller_test.rb b/test/controllers/recurring_todos_controller_test.rb index cccadb24..c9c2bce7 100644 --- a/test/controllers/recurring_todos_controller_test.rb +++ b/test/controllers/recurring_todos_controller_test.rb @@ -184,7 +184,7 @@ class RecurringTodosControllerTest < ActionController::TestCase # mark as active xhr :post, :toggle_check, :id=>1, :_source_view=>"" - + recurring_todo_1 = RecurringTodo.find(1) # reload seems to not work assert recurring_todo_1.active?, "recurring todo should be active but is #{recurring_todo_1.aasm.current_state}" @@ -260,7 +260,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "recurring_show_days_before"=>"0", "recurring_target"=>"due_date", "recurring_show_always" => "1", - "start_from"=>"1/10/2012", + "start_from"=>"1/10/2012", "weekly_every_x_week"=>"1", "weekly_return_monday"=>"w", "yearly_day_of_week"=>"0", @@ -379,9 +379,9 @@ class RecurringTodosControllerTest < ActionController::TestCase "tag_list"=>"one, two, three, four", format: :js assert_equal "new recurring pattern", assigns['recurring_todo'].description - assert_equal "2013-01-02", assigns['recurring_todo'].start_from.localtime.to_date.to_s + 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", todo.show_from.localtime.to_date.to_s + assert_equal "2013-01-02 00:00:00 +0000", todo.show_from.to_s end end @@ -419,9 +419,9 @@ class RecurringTodosControllerTest < ActionController::TestCase login_as(:admin_user) rt = recurring_todos(:call_bill_gates_every_day) - put :update, - "recurring_todo" => { - "description" => "changed", + put :update, + "recurring_todo" => { + "description" => "changed", "daily_selector" => "daily_every_x_day", "daily_every_x_days" => "2", "ends_on" => "no_end_date", @@ -433,7 +433,7 @@ class RecurringTodosControllerTest < ActionController::TestCase "recurring_todo_edit_start_from" => "2/1/2013", "end_date" => nil, "ends_on" => "no_end_date", - "id" => "#{rt.id}", + "id" => "#{rt.id}", "context_name" => "library", format: :js diff --git a/test/controllers/stats_controller_test.rb b/test/controllers/stats_controller_test.rb index d2140348..2c7e3485 100644 --- a/test/controllers/stats_controller_test.rb +++ b/test/controllers/stats_controller_test.rb @@ -49,7 +49,7 @@ class StatsControllerTest < ActionController::TestCase totals = assigns['stats'].totals assert_equal 4, totals.tags assert_equal 2, totals.unique_tags - assert_equal 2.weeks.ago.localtime.at_midnight, totals.first_action_at.localtime.at_midnight + assert_equal 2.week.ago.utc.at_midnight, totals.first_action_at.utc.at_midnight end def test_downdrill @@ -128,15 +128,15 @@ class StatsControllerTest < ActionController::TestCase # And they should be averaged over three months assert_equal 2/3.0, assigns['actions_done_avg_last12months_array'][1], "fourth month should be excluded" assert_equal 2/3.0, assigns['actions_done_avg_last12months_array'][2], "fourth month should be included" - + assert_equal (3)/3.0, assigns['actions_created_avg_last12months_array'][1], "one every month" assert_equal (4)/3.0, assigns['actions_created_avg_last12months_array'][2], "two in fourth month" - + # And the current month should be interpolated fraction = Time.zone.now.day.to_f / Time.zone.now.end_of_month.day.to_f assert_equal (2*(1/fraction)+2)/3.0, assigns['interpolated_actions_created_this_month'], "two this month and one in the last two months" assert_equal (2)/3.0, assigns['interpolated_actions_done_this_month'], "none this month and one two the last two months" - + # And totals should be calculated assert_equal 2, assigns['max'], "max of created or completed todos in one month" end @@ -168,7 +168,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -176,7 +176,7 @@ class StatsControllerTest < ActionController::TestCase assert_response :success # only tests relevant differences with actions_done_last_12months_data - + assert_equal 31, assigns['actions_done_last30days_array'].size, "30 complete days plus 1 for the current day" assert_equal 2, assigns['max'], "two actions created on one day is max" end @@ -185,31 +185,31 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data get :actions_done_lastyears_data assert_response :success - + # only tests difference with actions_done_last_12months_data - + # And the last two months are corrected assert_equal 2/3.0, assigns['actions_done_avg_last_months_array'][23] assert_equal 2/3.0, assigns['actions_done_avg_last_months_array'][24] end - + def test_actions_completion_time_data login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats - + # When I get the chart data get :actions_completion_time_data assert_response :success - + # do not test stuff already implicitly tested in other tests assert_equal 104, assigns['max_weeks'], "two years is 104 weeks (for completed_at)" assert_equal 3, assigns['max_actions'], "3 completed within one week" @@ -222,13 +222,13 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats - + # When I get the chart data get :actions_running_time_data assert_response :success - + # do not test stuff already implicitly tested in other tests assert_equal 17, assigns['max_weeks'], "there are actions in the first 17 weeks of this year" assert_equal 2, assigns['max_actions'], "2 actions running long together" @@ -241,13 +241,13 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats - + # When I get the chart data get :actions_open_per_week_data assert_response :success - + # do not test stuff already implicitly tested in other tests assert_equal 17, assigns['max_weeks'], "there are actions in the first 17 weeks of this year" assert_equal 4, assigns['max_actions'], "4 actions running together" @@ -258,12 +258,12 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # Given todo1 is deferred (i.e. not visible) @todo_today1.show_from = Time.zone.now + 1.week @todo_today1.save - + # When I get the chart data get :actions_visible_running_time_data assert_response :success @@ -281,7 +281,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -311,7 +311,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -335,12 +335,12 @@ class StatsControllerTest < ActionController::TestCase assert_equal 14, assigns['data'].values[9], "pie slices limited to max 10; last pie contains sum of rest (in percentage)" assert_equal "(others)", assigns['data'].labels[9], "pie slices limited to max 10; last slice contains label for others" end - + def test_actions_day_of_week_all_data login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -358,7 +358,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -376,7 +376,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -389,12 +389,12 @@ class StatsControllerTest < ActionController::TestCase assert_not_nil assigns['actions_creation_hour_array'] assert_not_nil assigns['actions_completion_hour_array'] end - + def test_show_selected_actions_from_chart_avrt login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -409,7 +409,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -424,7 +424,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -439,7 +439,7 @@ class StatsControllerTest < ActionController::TestCase login_as(:admin_user) @current_user = User.find(users(:admin_user).id) @current_user.todos.delete_all - + given_todos_for_stats # When I get the chart data @@ -451,7 +451,7 @@ class StatsControllerTest < ActionController::TestCase end private - + def given_todos_for_stats # Given two todos created today @todo_today1 = @current_user.todos.create!(:description => "created today1", :context => contexts(:office)) @@ -491,7 +491,7 @@ class StatsControllerTest < ActionController::TestCase def difference_in_days(date1, date2) return ((date1.at_midnight-date2.at_midnight)/(60*60*24)).to_i end - + # assumes date1 > date2 def difference_in_weeks(date1, date2) return difference_in_days(date1, date2) / 7 diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb index ed185ba9..910c6c7f 100644 --- a/test/controllers/todos_controller_test.rb +++ b/test/controllers/todos_controller_test.rb @@ -120,7 +120,7 @@ class TodosControllerTest < ActionController::TestCase assert_response :success assert_equal 3, @tagged end - + def test_find_tagged_with_terms_separated_with_dot login_as :admin_user create_todo(description: "test dotted tag", tag_list: "first.last, second") @@ -408,7 +408,7 @@ class TodosControllerTest < ActionController::TestCase ####### # defer - ####### + ####### def test_update_clearing_show_from_makes_todo_active t = Todo.find(1) @@ -437,7 +437,7 @@ class TodosControllerTest < ActionController::TestCase # given a todo in the tickler that should be activated travel_to 2.weeks.ago do create_todo( - description: "tickler", + description: "tickler", show_from: 1.week.from_now. in_time_zone(users(:admin_user).prefs.time_zone). strftime("#{users(:admin_user).prefs.date_format}")) @@ -740,14 +740,14 @@ class TodosControllerTest < ActionController::TestCase # locate the new todo in tickler new_todo = Todo.where(:recurring_todo_id => recurring_todo_1.id, :state => 'deferred').first - refute new_todo.nil?, "the todo should be in the tickler" + assert !new_todo.nil?, "the todo should be in the tickler" assert_equal "Call Bill Gates every day", new_todo.description assert_not_equal todo_1.id, new_todo.id, "check that the new todo is not the same as todo_1" - refute new_todo.show_from.nil?, "check that the new_todo is in the tickler to show next month" + assert !new_todo.show_from.nil?, "check that the new_todo is in the tickler to show next month" # do not use today here. It somehow gets messed up with the timezone calculation. - next_month = (today + 1.month).localtime.at_midnight + next_month = (Time.zone.now + 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 @@ -1024,13 +1024,13 @@ class TodosControllerTest < ActionController::TestCase private def create_todo(params={}) - defaults = { source_view: 'todo', - context_name: "library", project_name: "Build a working time machine", + defaults = { source_view: 'todo', + context_name: "library", project_name: "Build a working time machine", notes: "note", description: "a new todo", due: nil, tag_list: "a,b,c"} params=params.reverse_merge(defaults) - put :create, _source_view: params[:_source_view], + put :create, _source_view: params[:_source_view], context_name: params[:context_name], project_name: params[:project_name], tag_list: params[:tag_list], todo: {notes: params[:notes], description: params[:description], due: params[:due], show_from: params[:show_from]} end diff --git a/test/models/recurring_todos/abstract_repeat_pattern_test.rb b/test/models/recurring_todos/abstract_repeat_pattern_test.rb index d4d0adc8..fcb3e025 100644 --- a/test/models/recurring_todos/abstract_repeat_pattern_test.rb +++ b/test/models/recurring_todos/abstract_repeat_pattern_test.rb @@ -8,7 +8,7 @@ module RecurringTodos def setup super @admin = users(:admin_user) - end + end def test_pattern_builds_from_existing_recurring_todo rt = @admin.recurring_todos.first @@ -121,9 +121,9 @@ module RecurringTodos def test_determine_start travel_to Time.zone.local(2013,1,1) do rt = create_recurring_todo - assert_equal "2013-01-01", rt.send(:determine_start, nil).to_date.to_s(:db), "no previous date, use today" - assert_equal "2013-01-01", rt.send(:determine_start, nil, 1.day).to_date.to_s(:db), "no previous date, use today without offset" - assert_equal "2013-01-02", rt.send(:determine_start, Time.zone.now, 1.day).to_date.to_s(:db), "use previous date and offset" + assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil).to_s(:db), "no previous date, use today" + assert_equal "2013-01-01 00:00:00", rt.send(:determine_start, nil, 1.day).to_s(:db), "no previous date, use today without offset" + assert_equal "2013-01-02 00:00:00", rt.send(:determine_start, Time.zone.now, 1.day).to_s(:db), "use previous date and offset" end end @@ -131,14 +131,14 @@ module RecurringTodos rt = create_recurring_todo # march 2014 has 5 saturdays, the last will return the 5th - assert_equal "2014-03-01", rt.send(:get_xth_day_of_month, 1, 6, 3, 2014).to_date.to_s(:db) - assert_equal "2014-03-22", rt.send(:get_xth_day_of_month, 4, 6, 3, 2014).to_date.to_s(:db) - assert_equal "2014-03-29", rt.send(:get_xth_day_of_month, 5, 6, 3, 2014).to_date.to_s(:db) + assert_equal "2014-03-01 00:00:00", rt.send(:get_xth_day_of_month, 1, 6, 3, 2014).to_s(:db) + assert_equal "2014-03-22 00:00:00", rt.send(:get_xth_day_of_month, 4, 6, 3, 2014).to_s(:db) + assert_equal "2014-03-29 00:00:00", rt.send(:get_xth_day_of_month, 5, 6, 3, 2014).to_s(:db) # march 2014 has 4 fridays, the last will return the 4th - assert_equal "2014-03-07", rt.send(:get_xth_day_of_month, 1, 5, 3, 2014).to_date.to_s(:db) - assert_equal "2014-03-28", rt.send(:get_xth_day_of_month, 4, 5, 3, 2014).to_date.to_s(:db) - assert_equal "2014-03-28", rt.send(:get_xth_day_of_month, 5, 5, 3, 2014).to_date.to_s(:db) + assert_equal "2014-03-07 00:00:00", rt.send(:get_xth_day_of_month, 1, 5, 3, 2014).to_s(:db) + assert_equal "2014-03-28 00:00:00", rt.send(:get_xth_day_of_month, 4, 5, 3, 2014).to_s(:db) + assert_equal "2014-03-28 00:00:00", rt.send(:get_xth_day_of_month, 5, 5, 3, 2014).to_s(:db) assert_raise(RuntimeError, "should check on valid weekdays"){ rt.send(:get_xth_day_of_month, 5, 9, 3, 2014) } assert_raise(RuntimeError, "should check on valid count x"){ rt.send(:get_xth_day_of_month, 6, 5, 3, 2014) }