diff --git a/app/views/stats/_totals.rhtml b/app/views/stats/_totals.rhtml index fe83f388..02e2301d 100755 --- a/app/views/stats/_totals.rhtml +++ b/app/views/stats/_totals.rhtml @@ -8,12 +8,11 @@ Of those <%= @contexts.count(:conditions => ["hide = ?", false])%> are visible c <%= @contexts.count(:conditions => ["hide = ?", true]) %> are hidden contexts <% unless @actions.empty? -%> -
You have <%= @actions.count(:conditions => "completed_at IS NULL") %> incomplete actions of which -<%= @actions.count(:conditions => "completed_at IS NULL AND NOT show_from IS NULL") %> are -deferred actions.
+You have <%= @actions.count(:conditions => "completed_at IS NULL") %> incomplete actions +of which <%= @actions.count(:conditions => "completed_at IS NULL AND NOT show_from IS NULL") %> are deferred actions.
-Since your first action on <%= format_date(@first_action.created_at) %> you have -a total of <%= @actions.count %> actions. +
Since your first action on <%= format_date(@first_action.created_at) %> +you have a total of <%= @actions.count %> actions. <%= @actions.count(:conditions => "NOT completed_at IS NULL") %> of these are completed.
You have <%= @tags_count-%> tags placed on actions. Of those tags,
diff --git a/config/routes.rb b/config/routes.rb
index 2fd52714..4ae492bc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -65,6 +65,7 @@ ActionController::Routing::Routes.draw do |map|
map.preferences 'preferences', :controller => 'preferences', :action => 'index'
map.integrations 'integrations', :controller => 'integrations', :action => 'index'
+ map.stats 'stats', :controller => 'stats', :action => 'index'
map.search_plugin '/integrations/search_plugin.xml', :controller => 'integrations', :action => 'search_plugin', :format => 'xml'
map.resources :recurring_todos,
diff --git a/features/show_statistics.feature b/features/show_statistics.feature
new file mode 100644
index 00000000..50ca6954
--- /dev/null
+++ b/features/show_statistics.feature
@@ -0,0 +1,59 @@
+Feature Show statistics
+ In order to see what I have got done
+ As an user
+ I want see my statistic
+
+ Scenario: Show statistics with no history
+ Given I am logged in
+ And I have no todos
+ When I go to the statistics page
+ Then I should see "Totals"
+ And I should see " More statistics will appear here once you have added some actions."
+
+ Scenario: Show statistics with history
+ Given I am logged in
+ And I have 5 todos
+ And I have 2 deferred todos
+ And I have 2 completed todos
+ When I go to the statistics page
+ And I should see "You have 7 incomplete actions"
+ And I should see "of which 2 are deferred actions"
+ And I should see "you have a total of 9 actions"
+ And I should see "2 of these are completed"
+ Then I should see "Totals"
+ And I should see "Actions"
+ And I should see "Contexts"
+ And I should see "Projects"
+ And I should see "Tags"
+
+ Scenario: Click through to see chart of all actions per month
+ Given I am logged in
+ And I have 5 todos
+ When I go to the statistics page
+ And I click on the chart for actions done in the last 12 months
+ Then I should see a chart
+ And I should see "to return to the statistics page"
+
+ Scenario: Click through to see all incomplete actions of a week
+ Given I am logged in
+ And I have 5 todos
+ And I have 2 deferred todos
+ When I go to the statistics page
+ And I click on the chart for running time of all incomplete actions
+ Then I should see a chart
+ And I should see "Actions selected from week"
+ And I should see 7 todos
+ And I should see "to return to the statistics page"
+ And I should see "to show the actions from week 0 and further"
+
+ Scenario: Click through to see all incomplete visible actions of a week
+ Given I am logged in
+ And I have 5 todos
+ And I have 3 deferred todos
+ When I go to the statistics page
+ And I click on the chart for running time of all incomplete actions
+ Then I should see a chart
+ And I should see "Actions selected from week"
+ And I should see 5 todos
+ And I should see "to return to the statistics page"
+ And I should see "to show the actions from week 0 and further"
diff --git a/features/step_definitions/login_steps.rb b/features/step_definitions/login_steps.rb
new file mode 100644
index 00000000..04ef2c19
--- /dev/null
+++ b/features/step_definitions/login_steps.rb
@@ -0,0 +1,9 @@
+Given /^I am logged in$/ do
+ @current_user = User.create!(:login => "testuser", :password => "secret", :password_confirmation => "secret")
+ @current_user.create_preference
+ visit login_path
+ fill_in "login", :with => "testuser"
+ fill_in "password", :with => "secret"
+ click_button "Sign in"
+ response.body.should =~ /Login successful/m
+end
diff --git a/features/step_definitions/stats_steps.rb b/features/step_definitions/stats_steps.rb
new file mode 100644
index 00000000..21edddc8
--- /dev/null
+++ b/features/step_definitions/stats_steps.rb
@@ -0,0 +1,13 @@
+When /^I click on the chart for actions done in the last 12 months$/ do
+ # cannot really click the chart which is a swf
+ visit stats_path + "/actions_done_last_years"
+end
+
+Then /^I should see a chart$/ do
+ response.body.should =~ /open-flash-chart/m
+end
+
+When /^I click on the chart for running time of all incomplete actions$/ do
+ # cannot really click the chart which is a swf
+ visit stats_path + "/show_selected_actions_from_chart/art?index=0"
+end
diff --git a/features/step_definitions/todo_steps.rb b/features/step_definitions/todo_steps.rb
new file mode 100644
index 00000000..bd366f4c
--- /dev/null
+++ b/features/step_definitions/todo_steps.rb
@@ -0,0 +1,31 @@
+Given /^I have no todos$/ do
+ Todo.delete_all
+end
+
+Given /^I have ([0-9]+) todos$/ do |count|
+ context = @current_user.contexts.create!(:name => "context A")
+ count.to_i.downto 1 do |i|
+ @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}")
+ end
+end
+
+Given /^I have ([0-9]+) deferred todos$/ do |count|
+ context = @current_user.contexts.create!(:name => "context B")
+ count.to_i.downto 1 do |i|
+ @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}", :show_from => @current_user.time + 1.week)
+ end
+end
+
+Given /^I have ([0-9]+) completed todos$/ do |count|
+ context = @current_user.contexts.create!(:name => "context C")
+ count.to_i.downto 1 do |i|
+ todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}")
+ todo.complete!
+ end
+end
+
+Then /^I should see ([0-9]+) todos$/ do |count|
+ count.to_i.downto 1 do |i|
+ match_xpath "div["
+ end
+end
\ No newline at end of file
diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb
new file mode 100644
index 00000000..5bc407b4
--- /dev/null
+++ b/features/step_definitions/webrat_steps.rb
@@ -0,0 +1,107 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
+
+# Commonly used webrat steps
+# http://github.com/brynary/webrat
+
+Given /^I am on (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^I go to (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^I press "([^\"]*)"$/ do |button|
+ click_button(button)
+end
+
+When /^I follow "([^\"]*)"$/ do |link|
+ click_link(link)
+end
+
+When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
+ fill_in(field, :with => value)
+end
+
+When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
+ select(value, :from => field)
+end
+
+# Use this step in conjunction with Rail's datetime_select helper. For example:
+# When I select "December 25, 2008 10:00" as the date and time
+When /^I select "([^\"]*)" as the date and time$/ do |time|
+ select_datetime(time)
+end
+
+# Use this step when using multiple datetime_select helpers on a page or
+# you want to specify which datetime to select. Given the following view:
+# <%= f.label :preferred %>
+# <%= f.datetime_select :preferred %>
+# <%= f.label :alternative %>
+# <%= f.datetime_select :alternative %>
+# The following steps would fill out the form:
+# When I select "November 23, 2004 11:20" as the "Preferred" data and time
+# And I select "November 25, 2004 10:30" as the "Alternative" data and time
+When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
+ select_datetime(datetime, :from => datetime_label)
+end
+
+# Use this step in conjunction with Rail's time_select helper. For example:
+# When I select "2:20PM" as the time
+# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
+# will convert the 2:20PM to 14:20 and then select it.
+When /^I select "([^\"]*)" as the time$/ do |time|
+ select_time(time)
+end
+
+# Use this step when using multiple time_select helpers on a page or you want to
+# specify the name of the time on the form. For example:
+# When I select "7:30AM" as the "Gym" time
+When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
+ select_time(time, :from => time_label)
+end
+
+# Use this step in conjunction with Rail's date_select helper. For example:
+# When I select "February 20, 1981" as the date
+When /^I select "([^\"]*)" as the date$/ do |date|
+ select_date(date)
+end
+
+# Use this step when using multiple date_select helpers on one page or
+# you want to specify the name of the date on the form. For example:
+# When I select "April 26, 1982" as the "Date of Birth" date
+When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
+ select_date(date, :from => date_label)
+end
+
+When /^I check "([^\"]*)"$/ do |field|
+ check(field)
+end
+
+When /^I uncheck "([^\"]*)"$/ do |field|
+ uncheck(field)
+end
+
+When /^I choose "([^\"]*)"$/ do |field|
+ choose(field)
+end
+
+When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
+ attach_file(field, path)
+end
+
+Then /^I should see "([^\"]*)"$/ do |text|
+ response.should contain(text)
+end
+
+Then /^I should not see "([^\"]*)"$/ do |text|
+ response.should_not contain(text)
+end
+
+Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
+ field_labeled(label).should be_checked
+end
+
+Then /^I should be on (.+)$/ do |page_name|
+ URI.parse(current_url).path.should == path_to(page_name)
+end
diff --git a/features/support/env.rb b/features/support/env.rb
new file mode 100644
index 00000000..5d298d47
--- /dev/null
+++ b/features/support/env.rb
@@ -0,0 +1,17 @@
+# Sets up the Rails environment for Cucumber
+ENV["RAILS_ENV"] ||= "test"
+require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
+require 'cucumber/rails/world'
+require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
+Cucumber::Rails.use_transactional_fixtures
+Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
+ # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
+
+require 'webrat'
+
+Webrat.configure do |config|
+ config.mode = :rails
+end
+
+require 'cucumber/rails/rspec'
+require 'webrat/core/matchers'
diff --git a/features/support/paths.rb b/features/support/paths.rb
new file mode 100644
index 00000000..5adbc513
--- /dev/null
+++ b/features/support/paths.rb
@@ -0,0 +1,22 @@
+module NavigationHelpers
+ def path_to(page_name)
+ case page_name
+
+ when /the homepage/
+ root_path
+ when /the statistics page/
+ stats_path
+
+ # Add more page name => path mappings here
+
+ else
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
+ "Now, go and add a mapping in features/support/paths.rb"
+ end
+ end
+end
+
+World do |world|
+ world.extend NavigationHelpers
+ world
+end
diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake
new file mode 100644
index 00000000..f3fa7afe
--- /dev/null
+++ b/lib/tasks/cucumber.rake
@@ -0,0 +1,15 @@
+$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
+
+begin
+ require 'cucumber/rake/task'
+
+ Cucumber::Rake::Task.new(:features) do |t|
+ t.cucumber_opts = "--format pretty"
+ end
+ task :features => 'db:test:prepare'
+rescue LoadError
+ desc 'Cucumber rake task not available'
+ task :features do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
+ end
+end
diff --git a/script/cucumber b/script/cucumber
new file mode 100644
index 00000000..7f2b6a35
--- /dev/null
+++ b/script/cucumber
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+begin
+ load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
+rescue LoadError => e
+ raise unless e.to_s =~ /cucumber/
+ require "rubygems"
+ load File.join(Gem.bindir, "cucumber")
+end
\ No newline at end of file