From 6d1f0341110b79798bf45b5e803f06d0c6a022e2 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 17 Apr 2009 08:56:11 +0200 Subject: [PATCH] migrate login stories to cucumber features --- features/create_admin.feature | 32 ++++++++++ features/logging_in.feature | 25 ++++++++ features/step_definitions/login_steps.rb | 60 +++++++++++++++++++ .../step_definitions/page_navigation_steps.rb | 6 ++ features/step_definitions/user_steps.rb | 37 ++++++++++++ features/support/paths.rb | 6 ++ stories/login/first_run.story | 15 ----- stories/login/logging_in.story | 22 ------- stories/steps/login.rb | 55 ----------------- stories/steps/users.rb | 30 ---------- 10 files changed, 166 insertions(+), 122 deletions(-) create mode 100644 features/create_admin.feature create mode 100644 features/logging_in.feature create mode 100644 features/step_definitions/page_navigation_steps.rb create mode 100644 features/step_definitions/user_steps.rb delete mode 100644 stories/login/first_run.story delete mode 100644 stories/login/logging_in.story delete mode 100644 stories/steps/login.rb delete mode 100644 stories/steps/users.rb diff --git a/features/create_admin.feature b/features/create_admin.feature new file mode 100644 index 00000000..dfffe4b2 --- /dev/null +++ b/features/create_admin.feature @@ -0,0 +1,32 @@ +Feature: Signup new users + + In order to be able to administer Tracks + As a user who just installed Tracks + I want to create an admin account + + Scenario: Successful signup + Given no users exists + When I go to the homepage + Then I should be redirected to the signup page + When I successfully submit the signup form + Then I should be on the homepage + And I should be an admin + + Scenario: Signup should be refused when password and confirmation is not the same + Given no users exists + When I go to the signup page + And I submit signup form with dissimmilar password and confirmation + Then I should be redirected to the signup page + And I should see "Password doesn't match confirmation" + + Scenario: With public signups turned off, signup should be refused when an admin user exists + Given public signups are turned off + And an admin user exists + When I go to the signup page + Then I should see "You don't have permission to sign up for a new account." + + Scenario: With public signups turned on, signup should possible when an admin user exists + Given public signups are turned on + And an admin user exists + When I go to the signup page + Then I should see "Sign up a new user" \ No newline at end of file diff --git a/features/logging_in.feature b/features/logging_in.feature new file mode 100644 index 00000000..8cf7646c --- /dev/null +++ b/features/logging_in.feature @@ -0,0 +1,25 @@ +Feature: Existing user logging in + + In order to keep my things private + As an existing user + I want to log in with my username and password + + Scenario: Succesfull login + Given an admin user exists + When I go to the login page + And I successfully submit the login form as an admin user + Then I should be redirected to the home page + And I should see "Login successful" + + Scenario: Unsuccesfull login + Given an admin user exists + When I go to the login page + And I submit the login form as an admin user with an incorrect password + Then I should be on the login page + And I should see "Login unsuccessful" + + Scenario: Accessing a secured page when not logged in + Given an admin user exists + When I go to the home page + Then I should be redirected to the login page + \ No newline at end of file diff --git a/features/step_definitions/login_steps.rb b/features/step_definitions/login_steps.rb index 04ef2c19..13c002a2 100644 --- a/features/step_definitions/login_steps.rb +++ b/features/step_definitions/login_steps.rb @@ -7,3 +7,63 @@ Given /^I am logged in$/ do click_button "Sign in" response.body.should =~ /Login successful/m end + +Given /^public signups are turned (.*)$/ do |state| + case state + when 'on' + SITE_CONFIG['open_signups'] = true + when 'off' + SITE_CONFIG['open_signups'] = false + else + raise "public signups should be either 'on' or 'off'" + end +end + +When "I successfully submit the signup form" do + fill_in 'Desired login', :with => 'reinier' + fill_in 'Choose password', :with => 'abracadabra' + fill_in 'Confirm password', :with => 'abracadabra' + click_button +end + +When "I submit signup form with dissimmilar password and confirmation" do + fill_in 'Desired login', :with => 'reinier' + fill_in 'Choose password', :with => 'abracadabra' + fill_in 'Confirm password', :with => 'somethingelse' + click_button +end + +Then "I should be an admin" do + # just check on the presence of the menu item for managing users + Then "I should see \"Manage users\"" +end + +When "I submit the login form as an admin user with an incorrect password" do + Given "an admin user exists" + fill_in 'Login', :with => 'admin' + fill_in 'Password', :with => 'incorrectpass' + click_button +end + +When "I successfully submit the login form as an admin user" do + Given "an admin user exists" + fill_in 'Login', :with => 'admin' + fill_in 'Password', :with => 'abracadabra' + click_button +end + +When "Reinier visits the site" do + visits '/' +end + +Then "Reinier should see the tasks listing page" do + response.should have_tag('title', /list tasks/i) +end + +Then "Reinier should see the login page again" do + response.should have_tag('title', /login/i) +end + +Then "Reinier should see the message Login unsuccessful" do + should_see 'Login unsuccessful' +end \ No newline at end of file diff --git a/features/step_definitions/page_navigation_steps.rb b/features/step_definitions/page_navigation_steps.rb new file mode 100644 index 00000000..c767c190 --- /dev/null +++ b/features/step_definitions/page_navigation_steps.rb @@ -0,0 +1,6 @@ +Then /^I should be redirected to (.+?)$/ do |page_name| + request.headers['HTTP_REFERER'].should_not be_nil + request.headers['HTTP_REFERER'].should_not == request.request_uri + + Then "I should be on #{page_name}" +end \ No newline at end of file diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb new file mode 100644 index 00000000..be58a8f0 --- /dev/null +++ b/features/step_definitions/user_steps.rb @@ -0,0 +1,37 @@ +Given "no users exists" do + User.delete_all +end + +Given "an admin user exists" do + if @admin_user + @admin_user.destroy + end + @admin_user = User.create!(:login => 'admin', :password => 'abracadabra', :password_confirmation => 'abracadabra') + @admin_user.is_admin = true # is_admin is protected in user model + @admin_user.create_preference + @admin_user.preference.save + @admin_user.save +end + +Given "an admin user Reinier with the password abracadabra" do + @reinier = User.create!(:login => 'reinier', :password => 'abracadabra', :password_confirmation => 'abracadabra', :is_admin => true) + @reinier.create_preference +end + +Given "an admin user Reinier" do + Given "an admin user Reinier with the password abracadabra" +end + +Given "a logged in user Luis" do + @luis = User.create!(:login => 'luis', :password => 'sesame', :password_confirmation => 'sesame', :is_admin => false) + @luis.create_preference + logged_in_as @luis +end + +Given "Reinier is not logged in" do + #nothing to do +end + +Given "a visitor named Reinier" do + #nothing to do +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 5adbc513..370a6945 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -4,8 +4,14 @@ module NavigationHelpers when /the homepage/ root_path + when /the home page/ + root_path when /the statistics page/ stats_path + when /the signup page/ + "/users/new" + when /the login page/ + login_path # Add more page name => path mappings here diff --git a/stories/login/first_run.story b/stories/login/first_run.story deleted file mode 100644 index ca1ed89b..00000000 --- a/stories/login/first_run.story +++ /dev/null @@ -1,15 +0,0 @@ -Story: First run shows admin signup - - As a user who just installed Tracks - I want to create an admin account - So that I have control over all preferences and users - - Scenario: Successful signup - Given no users exist - And a visitor named Reinier - When Reinier visits the site - Then he should see a signup form - When Reinier successfully submits the signup form - Then Reinier should see the tasks listing page - And Reinier should be an admin - \ No newline at end of file diff --git a/stories/login/logging_in.story b/stories/login/logging_in.story deleted file mode 100644 index c6235100..00000000 --- a/stories/login/logging_in.story +++ /dev/null @@ -1,22 +0,0 @@ -Story: Existing user logging in - - As an existing user - I want to log in with my username and password - So that I can securely get things done - - Scenario: Login success - Given an admin user Reinier with the password abracadabra - And Reinier is not logged in - When Reinier visits the login page - And Reinier successfully submits the login form - Then Reinier should see the tasks listing page - And Reinier should see the message Login successful - - Scenario: Login failure - Given an admin user Reinier with the password abracadabra - And Reinier is not logged in - When Reinier visits the login page - And Reinier submits the login form with an incorrect password - Then Reinier should see the login page again - And Reinier should see the message Login unsuccessful - \ No newline at end of file diff --git a/stories/steps/login.rb b/stories/steps/login.rb deleted file mode 100644 index 8729a5e8..00000000 --- a/stories/steps/login.rb +++ /dev/null @@ -1,55 +0,0 @@ -steps_for :login do - include_steps_for :users - - When "Reinier submits the login form with an incorrect password" do - fills_in 'Login', :with => 'reinier' - fills_in 'Password', :with => 'incorrectpass' - clicks_button - end - - When "Reinier visits the login page" do - visits '/login' - end - - When "Reinier successfully submits the login form" do - fills_in 'Login', :with => 'reinier' - fills_in 'Password', :with => 'abracadabra' - clicks_button - end - - When "Reinier visits the site" do - visits '/' - end - - When "Reinier successfully submits the signup form" do - fills_in 'Desired login', :with => 'reinier' - fills_in 'Choose password', :with => 'abracadabra' - fills_in 'Confirm password', :with => 'abracadabra' - clicks_button - end - - Then "he should see a signup form" do - should_see 'create an admin account' - end - - Then "Reinier should see the tasks listing page" do - response.should have_tag('title', /list tasks/i) - end - - Then "Reinier should be an admin" do - response.should have_tag('a', /Admin/i) - end - - Then "Reinier should see the message Login successful" do - should_see 'Login successful' - end - - Then "Reinier should see the login page again" do - response.should have_tag('title', /login/i) - end - - Then "Reinier should see the message Login unsuccessful" do - should_see 'Login unsuccessful' - end - -end \ No newline at end of file diff --git a/stories/steps/users.rb b/stories/steps/users.rb deleted file mode 100644 index 834c41d0..00000000 --- a/stories/steps/users.rb +++ /dev/null @@ -1,30 +0,0 @@ -steps_for :users do - - Given "an admin user Reinier with the password abracadabra" do - @reinier = User.create!(:login => 'reinier', :password => 'abracadabra', :password_confirmation => 'abracadabra', :is_admin => true) - @reinier.create_preference - end - - Given "an admin user Reinier" do - Given "an admin user Reinier with the password abracadabra" - end - - Given "a logged in user Luis" do - @luis = User.create!(:login => 'luis', :password => 'sesame', :password_confirmation => 'sesame', :is_admin => false) - @luis.create_preference - logged_in_as @luis - end - - Given "no users exist" do - User.delete_all - end - - Given "Reinier is not logged in" do - #nothing to do - end - - Given "a visitor named Reinier" do - #nothing to do - end - -end \ No newline at end of file