From d14a2a808dba4877fe7307901d246ba37cbd0143 Mon Sep 17 00:00:00 2001 From: Sebastian Fischmeister Date: Mon, 30 Jan 2012 09:56:58 -0500 Subject: [PATCH] cucumber tests for the review mode --- features/review.feature | 36 ++++++++++++++++++++++ features/step_definitions/project_steps.rb | 7 +++++ features/step_definitions/review_steps.rb | 9 ++++++ test/unit/project_test.rb | 12 +++++++- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 features/review.feature create mode 100644 features/step_definitions/review_steps.rb diff --git a/features/review.feature b/features/review.feature new file mode 100644 index 00000000..6ba74cd4 --- /dev/null +++ b/features/review.feature @@ -0,0 +1,36 @@ +Feature: Reviewing projects + In order to keep the todos and projects up to date + As a Tracks user + I want to review my projects + + Background: + Given the following user record + | login | password | is_admin | + | testuser | secret | false | + And I have logged in as "testuser" with password "secret" + + Scenario: I see stalled projects + Given I have no projects + Given I have a project "stalled_project" with 0 todos + When I go to the review page + Then I see the project "stalled_project" in the "stalled" list + + Scenario: I see blocked projects + Given I have no projects + Given I have a project "blocked_project" with 1 deferred todos + When I go to the review page + Then I see the project "blocked_project" in the "blocked" list + + Scenario: I see dated projects + Given I have no projects + Given I have an outdated project "dated_project" with 1 todos + When I go to the review page + Then I see the project "dated_project" in the "review" list + + Scenario: The review list of projects contains all projects + Given I have no projects + Given I have a project "stalled_project" with 0 todos + Given I have a project "blocked_project" with 1 deferred todos + Given I have an outdated project "dated_project" with 1 todos + When I go to the review page + And the badge should show 5 ## note that stalled and blocked projects are also up-to-date listed diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index ffbf3aaa..132f7b92 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -1,3 +1,10 @@ +Given /^I have an outdated project "([^"]*)" with (\d+) todos$/ do |project_name, num_todos| + Given "I have a project \"#{project_name}\" with #{num_todos} todos" + @project = @current_user.projects.find_by_name(project_name) + @project.last_reviewed = @current_user.time - @current_user.prefs.review_period.days-1 + @project.save +end + Given /^I have a project "([^\"]*)" with ([0-9]+) todos$/ do |project_name, num_todos| @context = @current_user.contexts.find_or_create_by_name("Context A") @project = @current_user.projects.create!(:name => project_name) diff --git a/features/step_definitions/review_steps.rb b/features/step_definitions/review_steps.rb new file mode 100644 index 00000000..5b9fc699 --- /dev/null +++ b/features/step_definitions/review_steps.rb @@ -0,0 +1,9 @@ +Then /^I see the project "([^"]*)" in the "([^"]*)" list$/ do |name, state| + project = @current_user.projects.find_by_name(name) + project.should_not be_nil + + xpath = "//div[@id='list-#{state}-projects']//div[@id='project_#{project.id}']" + response.should have_xpath(xpath) +end + + diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index bafa5425..51179b31 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -68,7 +68,17 @@ class ProjectTest < ActiveSupport::TestCase assert_equal :active, @timemachine.aasm_current_state assert @timemachine.active? end - + + def test_review_project + assert_nil @timemachine.last_reviewed + assert @timemachine.needs_review?(nil) + end + + def test_review_completedprojects + @timemachine.complete! + assert !@timemachine.needs_review?(nil) + end + def test_complete_project assert_nil @timemachine.completed_at @timemachine.complete!