migrate login stories to cucumber features

This commit is contained in:
Reinier Balt 2009-04-17 08:56:11 +02:00
parent 7bdd365ff3
commit 6d1f034111
10 changed files with 166 additions and 122 deletions

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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