mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-23 10:40:13 +01:00
fix stats_controller tests when running them in the first week of a month
need to figure out how to set system date from tests so that the test are not using data relative from the day you run the tests
This commit is contained in:
parent
796685072d
commit
bb91ea6e32
1 changed files with 16 additions and 11 deletions
|
|
@ -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"
|
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 :-(
|
# 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
|
# FIXME: make testdata not relative of today to avoid crossing end_of_month
|
||||||
too_early = Time.zone.now.day <= 8 ? 1 : 0
|
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"
|
assigns['actions_created_last12months_array'].each do |e|
|
||||||
assert_equal 1+too_early, assigns['actions_created_last12months_array'][2], "there should be one todo in two month ago"
|
puts "#{e} \t"
|
||||||
assert_equal 1, assigns['actions_created_last12months_array'][3], "there should be one todo in three month ago"
|
end
|
||||||
assert_equal 2, assigns['actions_created_last12months_array'][4], "there should be two todos (1 created & 1 done) in four month ago"
|
|
||||||
|
|
||||||
assert_equal 1, assigns['actions_done_last12months_array'][1], "there should be one completed todo one-two 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_done_last12months_array'][2], "there should be one completed todo two-three months ago"
|
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_done_last12months_array'][4], "there should be one completed todo four-five months 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
|
# 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'][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 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 (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"
|
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
|
# And the current month should be interpolated
|
||||||
fraction = Time.zone.now.day.to_f / Time.zone.now.end_of_month.day.to_f
|
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*(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/3.0, assigns['interpolated_actions_done_this_month'], "none this month and one two 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
|
# And totals should be calculated
|
||||||
assert_equal 2, assigns['max'], "max of created or completed todos in one month"
|
assert_equal 2, assigns['max'], "max of created or completed todos in one month"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue