From c9be43b2c8134589c5451ba61ec82283aabe522d Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 29 Jul 2010 18:06:30 +0200 Subject: [PATCH] add tests for #886. --- app/views/contexts/_context_state_group.rhtml | 2 +- features/contexts_manage.feature | 20 +++++++++++++++ features/step_definitions/context_steps.rb | 25 ++++++++++++++++++- features/support/world.rb | 4 +++ spec/factories/factories.rb | 6 +++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/app/views/contexts/_context_state_group.rhtml b/app/views/contexts/_context_state_group.rhtml index 835d2f44..58e51cf7 100644 --- a/app/views/contexts/_context_state_group.rhtml +++ b/app/views/contexts/_context_state_group.rhtml @@ -1,4 +1,4 @@ -
+

<%= context_state_group.length %><%= state.titlecase %> Contexts

Currently there are no <%= state %> contexts

diff --git a/features/contexts_manage.feature b/features/contexts_manage.feature index 57002fcf..64cd4ed8 100644 --- a/features/contexts_manage.feature +++ b/features/contexts_manage.feature @@ -48,3 +48,23 @@ Feature: Manage contexts And he should see that a context named "@laptop" is not present And he should see that a context named "@ipad" is present And the badge should show 1 + + @selenium, @wip + Scenario: Add new context + Given I have the following contexts + | name | hide | + | @ipad | true | + | @home | false | + When I go to the contexts page + And I add a new context "@phone" + Then I should see the context "@phone" under "active" + + @selenium, @wip + Scenario: Add new hidden context + Given I have the following contexts + | name | hide | + | @ipad | true | + | @home | false | + When I go to the contexts page + And I add a new hidden context "@hidden" + Then I should see the context "@hidden" under "hidden" diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb index 532a9f0d..671b6a70 100644 --- a/features/step_definitions/context_steps.rb +++ b/features/step_definitions/context_steps.rb @@ -20,6 +20,13 @@ Given /^I have a context "([^\"]*)" with (.*) actions$/ do |context_name, number end end +Given /^I have the following contexts$/ do |table| + Context.delete_all + table.hashes.each do |hash| + context = Factory(:context, hash) + end +end + When /^I visit the context page for "([^\"]*)"$/ do |context_name| context = @current_user.contexts.find_by_name(context_name) context.should_not be_nil @@ -61,6 +68,17 @@ When /^I edit the context to rename it to "([^\"]*)"$/ do |new_name| end end +When /^I add a new context "([^"]*)"$/ do |context_name| + fill_in "context[name]", :with => context_name + submit_new_context_form +end + +When /^I add a new hidden context "([^"]*)"$/ do |context_name| + fill_in "context[name]", :with => context_name + check "context_hide" + submit_new_context_form +end + Then /^I should see the context name is "([^\"]*)"$/ do |context_name| Then "I should see \"#{context_name}\"" end @@ -71,4 +89,9 @@ end Then /^he should see that a context named "([^\"]*)" is not present$/ do |context_name| Then "I should not see \"#{context_name} (\"" -end \ No newline at end of file +end + +Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state| + context = Context.find_by_name(context_name) + response.should have_xpath("//div[@id='list-contexts-#{state}']//div[@id='context_#{context.id}']") +end diff --git a/features/support/world.rb b/features/support/world.rb index 7bdf463a..20870a4a 100644 --- a/features/support/world.rb +++ b/features/support/world.rb @@ -7,6 +7,10 @@ module TracksStepHelper selenium.click("xpath=//form[@id='todo-form-new-action']//button[@id='todo_new_action_submit']", :wait_for => :ajax, :javascript_framework => :jquery) end + def submit_new_context_form + selenium.click("xpath=//form[@id='context-form']//button[@id='context_new_submit']", :wait_for => :ajax, :javascript_framework => :jquery) + end + end World(TracksStepHelper) \ No newline at end of file diff --git a/spec/factories/factories.rb b/spec/factories/factories.rb index fb344734..6a230605 100644 --- a/spec/factories/factories.rb +++ b/spec/factories/factories.rb @@ -3,4 +3,10 @@ Factory.define :user do |u| u.password "secret" u.password_confirmation { |user| user.password } u.is_admin false +end + +Factory.define :context do |c| + c.sequence(:name) { |n| "testcontext#{n}" } + c.hide false + c.created_at Time.now.utc end \ No newline at end of file