diff --git a/Gemfile b/Gemfile index 5325880c..e78fa645 100644 --- a/Gemfile +++ b/Gemfile @@ -27,8 +27,7 @@ group :assets do gem 'coffee-rails' # See https://github.com/sstephenson/execjs#readme for more supported runtimes - gem 'therubyracer', :platform => :ruby - gem "libv8" + gem 'therubyracer', :platform => :ruby, :require => "v8" gem 'uglifier' end @@ -58,6 +57,7 @@ group :test do gem "database_cleaner" gem "aruba" gem "simplecov" + gem "timecop" # Note that > 2.14 has problems, see: # https://code.google.com/p/selenium/issues/detail?id=3075 diff --git a/Gemfile.lock b/Gemfile.lock index 336cdd6d..a73da8c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,13 +9,13 @@ GEM remote: https://rubygems.org/ specs: RedCloth (4.2.9) - aasm (3.0.14) - actionmailer (3.2.9) - actionpack (= 3.2.9) + aasm (3.0.15) + actionmailer (3.2.10) + actionpack (= 3.2.10) mail (~> 2.4.4) - actionpack (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) + actionpack (3.2.10) + activemodel (= 3.2.10) + activesupport (= 3.2.10) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -23,18 +23,18 @@ GEM rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.9) - activesupport (= 3.2.9) + activemodel (3.2.10) + activesupport (= 3.2.10) builder (~> 3.0.0) - activerecord (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) + activerecord (3.2.10) + activemodel (= 3.2.10) + activesupport (= 3.2.10) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) - activesupport (3.2.9) + activeresource (3.2.10) + activemodel (= 3.2.10) + activesupport (= 3.2.10) + activesupport (3.2.10) i18n (~> 0.6) multi_json (~> 1.0) acts_as_list (0.1.9) @@ -47,9 +47,9 @@ GEM bcrypt-ruby (3.0.1) bluecloth (2.2.0) builder (3.0.4) - bullet (4.2.0) + bullet (4.3.0) uniform_notifier - capybara (2.0.1) + capybara (2.0.2) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) @@ -100,8 +100,8 @@ GEM jquery-rails (2.1.4) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.7.5) - libv8 (3.11.8.4) + json (1.7.6) + libv8 (3.11.8.9) libwebsocket (0.1.7.1) addressable websocket @@ -126,19 +126,19 @@ GEM rack rack-test (0.6.2) rack (>= 1.0) - rails (3.2.9) - actionmailer (= 3.2.9) - actionpack (= 3.2.9) - activerecord (= 3.2.9) - activeresource (= 3.2.9) - activesupport (= 3.2.9) + rails (3.2.10) + actionmailer (= 3.2.10) + actionpack (= 3.2.10) + activerecord (= 3.2.10) + activeresource (= 3.2.10) + activesupport (= 3.2.10) bundler (~> 1.0) - railties (= 3.2.9) + railties (= 3.2.10) rails_autolink (1.0.9) rails (~> 3.1) - railties (3.2.9) - actionpack (= 3.2.9) - activesupport (= 3.2.9) + railties (3.2.10) + actionpack (= 3.2.10) + activesupport (= 3.2.10) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) @@ -152,7 +152,7 @@ GEM rubyzip (0.9.9) sanitize (2.0.3) nokogiri (>= 1.4.4, < 1.6) - sass (3.2.4) + sass (3.2.5) sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) @@ -175,10 +175,12 @@ GEM swf_fu (2.0.3) coffee-script rails (>= 3.1) - therubyracer (0.11.0) + therubyracer (0.11.1) + libv8 (~> 3.11.8.7) ref thor (0.16.0) tilt (1.3.3) + timecop (0.5.7) tolk (1.3.4) will_paginate ya2yaml (~> 0.26) @@ -189,7 +191,7 @@ GEM uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) - uniform_notifier (1.1.0) + uniform_notifier (1.1.1) websocket (1.0.6) will_paginate (3.0.3) xpath (1.0.0) @@ -216,7 +218,6 @@ DEPENDENCIES formatize htmlentities jquery-rails - libv8 mongrel (>= 1.2.0.pre2) mysql2 rack-mini-profiler @@ -229,6 +230,7 @@ DEPENDENCIES sqlite3 swf_fu therubyracer + timecop tolk uglifier will_paginate diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index e5f2f6e2..4c05d78e 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -104,7 +104,7 @@ class StatsController < ApplicationController @actions_completion_time = current_user.todos.completed.select("completed_at, created_at").reorder("completed_at DESC" ) # convert to array and fill in non-existing weeks with 0 - @max_weeks = difference_in_weeks(@today, @actions_completion_time.last.completed_at) + @max_weeks = @actions_completion_time.last ? difference_in_weeks(@today, @actions_completion_time.last.completed_at) : 1 @actions_completed_per_week_array = convert_to_weeks_running_array(@actions_completion_time, @max_weeks+1) # stop the chart after 10 weeks diff --git a/features/support/world.rb b/features/support/world.rb index cfb129b8..c63659f6 100644 --- a/features/support/world.rb +++ b/features/support/world.rb @@ -129,7 +129,7 @@ module TracksStepHelper start_time = Time.now page.evaluate_script('jQuery.isReady&&jQuery.active==0').class.should_not eql(String) until(page.evaluate_script('jQuery.isReady&&jQuery.active==0') || (start_time + 5.seconds) < Time.now) - sleep 1 + sleep 0.25 end end diff --git a/features/view_done.feature b/features/view_done.feature index 6b0e50bd..0b9d18a4 100644 --- a/features/view_done.feature +++ b/features/view_done.feature @@ -90,7 +90,7 @@ Feature: Show done When I follow "Show all" Then I should see the page selector And I should see "40 (1-20)" - When I follow "2" + When I select the second page Then I should be on the done projects page And the page should be "2" @@ -109,7 +109,7 @@ Feature: Show done And I follow "Show all" Then I should see the page selector And I should see "40 (1-20)" - When I follow "2" + When I select the second page Then I should be on the done recurring todos page And the page should be "2" diff --git a/lib/tracks/done_todos.rb b/lib/tracks/done_todos.rb index c1692b6b..e5374dab 100644 --- a/lib/tracks/done_todos.rb +++ b/lib/tracks/done_todos.rb @@ -10,7 +10,7 @@ class DoneTodos end def self.done_this_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) - done_between(todos, Time.zone.now.beginning_of_day, Time.zone.now.beginning_of_week) + done_between(todos, includes, Time.zone.now.beginning_of_day, Time.zone.now.beginning_of_week) end def self.done_this_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) diff --git a/test/functional/stats_controller_test.rb b/test/functional/stats_controller_test.rb index fc8cee98..081d1f0b 100644 --- a/test/functional/stats_controller_test.rb +++ b/test/functional/stats_controller_test.rb @@ -89,52 +89,49 @@ class StatsControllerTest < ActionController::TestCase end def test_actions_done_last12months_data - login_as(:admin_user) - @current_user = User.find(users(:admin_user).id) - @current_user.todos.delete_all + Timecop.travel(Time.local(2013, 1, 15)) do + login_as(:admin_user) + @current_user = User.find(users(:admin_user).id) + @current_user.todos.delete_all - given_todos_for_stats + given_todos_for_stats - # When I get the chart data - get :actions_done_last12months_data - assert_response :success + # When I get the chart data + get :actions_done_last12months_data + assert_response :success - # Then the todos for the chart should be retrieved - assert_not_nil assigns['actions_done_last12months'] - assert_not_nil assigns['actions_created_last12months'] - assert_equal 7, assigns['actions_created_last12months'].count, "very old todo should not be retrieved" + # Then the todos for the chart should be retrieved + assert_not_nil assigns['actions_done_last12months'] + assert_not_nil assigns['actions_created_last12months'] + assert_equal 7, assigns['actions_created_last12months'].count, "very old todo should not be retrieved" - # And they should be totalled in a hash - assert_equal 2, assigns['actions_created_last12months_array'][0], "there should be two todos in current month" + # And they should be totalled in a hash + 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, assigns['actions_created_last12months_array'][1], "there should be one todo in previous month" + assert_equal 1, 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" - 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], "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_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-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-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" + # 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 end def test_actions_done_last30days_data