From f42a5d3bdd0e5d85b9bb711ea32539be2a7111d5 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 3 Jan 2014 15:59:44 +0100 Subject: [PATCH] fix false test error using timecop --- .../recurring_todos_controller_test.rb | 93 ++++++++++--------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/test/functional/recurring_todos_controller_test.rb b/test/functional/recurring_todos_controller_test.rb index 8cdabcee..0068df35 100644 --- a/test/functional/recurring_todos_controller_test.rb +++ b/test/functional/recurring_todos_controller_test.rb @@ -126,56 +126,59 @@ class RecurringTodosControllerTest < ActionController::TestCase # this test is a duplicate of the unit test. Only this test covers the # codepath in the controllers - login_as(:admin_user) + Timecop.travel(Time.local(2012,1,1)) do - orig_rt_count = RecurringTodo.count - orig_todo_count = Todo.count + login_as(:admin_user) - put :create, - "context_name"=>"library", - "project_name"=>"Build a working time machine", - "recurring_todo" => - { - "daily_every_x_days"=>"1", - "daily_selector"=>"daily_every_x_day", - "description"=>"new recurring pattern", - "end_date" => "", - "ends_on" => "no_end_date", - "monthly_day_of_week" => "1", - "monthly_every_x_day" => "22", - "monthly_every_x_month2" => "1", - "monthly_every_x_month" => "1", - "monthly_every_xth_day"=>"1", - "monthly_selector"=>"monthly_every_x_day", - "notes"=>"with some notes", - "number_of_occurences" => "", - "recurring_period"=>"yearly", - "recurring_show_days_before"=>"0", - "recurring_target"=>"due_date", - "recurring_show_always" => "1", - "start_from"=>"1/10/2012", # adjust after 2012 - "weekly_every_x_week"=>"1", - "weekly_return_monday"=>"w", - "yearly_day_of_week"=>"0", - "yearly_every_x_day"=>"22", - "yearly_every_xth_day"=>"5", - "yearly_month_of_year2"=>"3", - "yearly_month_of_year"=>"10", - "yearly_selector"=>"yearly_every_xth_day" - }, - "tag_list"=>"one, two, three, four" + orig_rt_count = RecurringTodo.count + orig_todo_count = Todo.count - # check new recurring todo added - assert_equal orig_rt_count+1, RecurringTodo.count - # check new todo added - assert_equal orig_todo_count+1, Todo.count + put :create, + "context_name"=>"library", + "project_name"=>"Build a working time machine", + "recurring_todo" => + { + "daily_every_x_days"=>"1", + "daily_selector"=>"daily_every_x_day", + "description"=>"new recurring pattern", + "end_date" => "", + "ends_on" => "no_end_date", + "monthly_day_of_week" => "1", + "monthly_every_x_day" => "22", + "monthly_every_x_month2" => "1", + "monthly_every_x_month" => "1", + "monthly_every_xth_day"=>"1", + "monthly_selector"=>"monthly_every_x_day", + "notes"=>"with some notes", + "number_of_occurences" => "", + "recurring_period"=>"yearly", + "recurring_show_days_before"=>"0", + "recurring_target"=>"due_date", + "recurring_show_always" => "1", + "start_from"=>"1/10/2012", # adjust after 2012 + "weekly_every_x_week"=>"1", + "weekly_return_monday"=>"w", + "yearly_day_of_week"=>"0", + "yearly_every_x_day"=>"22", + "yearly_every_xth_day"=>"5", + "yearly_month_of_year2"=>"3", + "yearly_month_of_year"=>"10", + "yearly_selector"=>"yearly_every_xth_day" + }, + "tag_list"=>"one, two, three, four" - # find the newly created todo - new_todo = Todo.find_by_description("new recurring pattern") - assert !new_todo.nil? + # check new recurring todo added + assert_equal orig_rt_count+1, RecurringTodo.count + # check new todo added + assert_equal orig_todo_count+1, Todo.count - # the date should be 31 march 2013 - assert_equal Time.zone.local(2013,3,31), new_todo.due + # find the newly created todo + new_todo = Todo.find_by_description("new recurring pattern") + assert !new_todo.nil? + + # the date should be 31 march 2013 + assert_equal Time.zone.local(2013,3,31), new_todo.due + end end def test_recurring_todo_with_due_date_and_show_always