diff --git a/test/functional/stats_controller_test.rb b/test/functional/stats_controller_test.rb index 3dacfa72..1861a153 100644 --- a/test/functional/stats_controller_test.rb +++ b/test/functional/stats_controller_test.rb @@ -108,29 +108,34 @@ class StatsControllerTest < ActionController::TestCase assert_equal 2, assigns['actions_created_last12months_array'][0], "there should be two todos in current month" # these test use relative dates. It will go wrong when the data is [1-8] of the month :-( + # in this case we need to check for a month further (i.e. too_early==1) # FIXME: make testdata not relative of today to avoid crossing end_of_month too_early = Time.zone.now.day <= 8 ? 1 : 0 - assert_equal 1-too_early, assigns['actions_created_last12months_array'][1], "there should be one todo in previous month" - assert_equal 1+too_early, assigns['actions_created_last12months_array'][2], "there should be one todo in two month ago" - assert_equal 1, assigns['actions_created_last12months_array'][3], "there should be one todo in three month ago" - assert_equal 2, assigns['actions_created_last12months_array'][4], "there should be two todos (1 created & 1 done) in four month ago" + assigns['actions_created_last12months_array'].each do |e| + puts "#{e} \t" + end - assert_equal 1, assigns['actions_done_last12months_array'][1], "there should be one completed todo one-two months ago" - assert_equal 1, assigns['actions_done_last12months_array'][2], "there should be one completed todo two-three months ago" - assert_equal 1, assigns['actions_done_last12months_array'][4], "there should be one completed todo four-five months ago" + assert_equal 1, assigns['actions_created_last12months_array'][1+too_early], "there should be one todo in previous month" + assert_equal 1, assigns['actions_created_last12months_array'][2+too_early], "there should be one todo in two month ago" + assert_equal 1, assigns['actions_created_last12months_array'][3+too_early], "there should be one todo in three month ago" + assert_equal 2, assigns['actions_created_last12months_array'][4+too_early], "there should be two todos (1 created & 1 done) in four month ago" + + assert_equal 1, assigns['actions_done_last12months_array'][1+too_early], "there should be one completed todo one-two months ago" + assert_equal 1, assigns['actions_done_last12months_array'][2+too_early], "there should be one completed todo two-three months ago" + assert_equal 1, assigns['actions_done_last12months_array'][4+too_early], "there should be one completed todo four-five months ago" # 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+too_early)/3.0, assigns['actions_created_avg_last12months_array'][2], "two in fourth month" + assert_equal (3-too_early)/3.0, assigns['actions_created_avg_last12months_array'][1], "one every month" + assert_equal (4-too_early)/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" + assert_equal (2*(1/fraction)+2-too_early)/3.0, assigns['interpolated_actions_created_this_month'], "two this month and one in the last two months" + assert_equal (2-too_early)/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"