Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 102 additions & 62 deletions features/step_definitions/user_steps.rb
Original file line number Diff line number Diff line change
@@ -1,106 +1,146 @@
Given /^no user exists with an email of "(.*)"$/ do |email|
User.find(:first, :conditions => { :email => email }).should be_nil
### UTILITY METHODS ###
def valid_user
@user ||= { :name => "Testy McUserton", :email => "testy@userton.com",
:password => "please", :password_confirmation => "please"}
end

Given /^I am a user named "([^"]*)" with an email "([^"]*)" and password "([^"]*)"$/ do |name, email, password|
User.new(:name => name,
:email => email,
:password => password,
:password_confirmation => password).save!
def sign_up user
visit '/users/sign_up'
fill_in "Name", :with => user[:name]
fill_in "Email", :with => user[:email]
fill_in "Password", :with => user[:password]
fill_in "Password confirmation", :with => user[:password_confirmation]
click_button "Sign up"
end

Then /^I should be already signed in$/ do
step %{I should see "Logout"}
def sign_in user
visit '/users/sign_in'
fill_in "Email", :with => user[:email]
fill_in "Password", :with => user[:password]
click_button "Sign in"
end

Given /^I am signed up as "(.*)\/(.*)"$/ do |email, password|
step %{I am not logged in}
step %{I go to the sign up page}
step %{I fill in "Email" with "#{email}"}
step %{I fill in "Password" with "#{password}"}
step %{I fill in "Password confirmation" with "#{password}"}
step %{I press "Sign up"}
step %{I should see "You have signed up successfully. If enabled, a confirmation was sent to your e-mail."}
step %{I am logout}
### GIVEN ###
Given /^I am not logged in$/ do
visit '/users/sign_out'
end

Given /^I am logout$/ do
step %{I sign out}
Given /^I am logged in$/ do
sign_up valid_user
end

Given /^I am not logged in$/ do
step %{I sign out}
Given /^I exist as a user$/ do
sign_up valid_user
visit '/users/sign_out'
end

When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
step %{I am not logged in}
step %{I go to the sign in page}
step %{I fill in "Email" with "#{email}"}
step %{I fill in "Password" with "#{password}"}
step %{I press "Sign in"}
Given /^I do not exist as a user$/ do
User.find(:first, :conditions => { :email => valid_user[:email] }).should be_nil
visit '/users/sign_out'
end

Then /^I should be signed in$/ do
step %{I should see "Signed in successfully."}
### WHEN ###
When /^I sign out$/ do
visit '/users/sign_out'
end

When /^I return next time$/ do
step %{I go to the home page}
When /^I sign up with valid user data$/ do
sign_up valid_user
end

Then /^I should be signed out$/ do
step %{I should see "Sign up"}
step %{I should see "Login"}
step %{I should not see "Logout"}
When /^I sign up with an invalid email$/ do
user = valid_user.merge(:email => "notanemail")
sign_up user
end

Then /^I sign out$/ do
visit '/users/sign_out'
When /^I sign up without a confirmed password$/ do
user = valid_user.merge(:password_confirmation => "")
sign_up user
end

When /^I go to the sign in page$/ do
visit '/users/sign_in'
When /^I sign up without a password$/ do
user = valid_user.merge(:password => "")
sign_up user
end

When /^I sign up with a mismatched password confirmation$/ do
user = valid_user.merge(:password_confirmation => "please123")
sign_up user
end

Then /^I should see "([^"]*)"$/ do |text|
page.should have_content(text)
When /^I return to the site$/ do
visit '/'
end

Then /^I should not see "([^"]*)"$/ do |text|
page.should_not have_content(text)
When /^I sign in with a wrong password$/ do
user = valid_user.merge(:password => "wrongpass")
sign_in user
end

Then /^I go to the home page$/ do
visit '/'
When /^I sign in with valid credintials$/ do
sign_in valid_user
end

When /^I edit my account details$/ do
click_link "Edit account"
fill_in "Name", :with => "newname"
fill_in "Current password", :with => valid_user[:password]
click_button "Update"
end

Given /^I am on the home page$/ do
When /^I look at the list of users$/ do
visit '/'
end

Given /^I go to the sign up page$/ do
visit '/users/sign_up'
### THEN ###
Then /^I should be signed in$/ do
page.should have_content "Logout"
page.should_not have_content "Sign up"
page.should_not have_content "Login"
end

Given /^I fill in the following:$/ do |table|
# table is a Cucumber::Ast::Table
table.rows_hash.each do |key, value|
fill_in(key, :with => value)
end
Then /^I should be signed out$/ do
page.should have_content "Sign up"
page.should have_content "Login"
page.should_not have_content "Logout"
end

When /^I press "([^"]*)"$/ do |label|
click_button label
Then /^I should see a succesfull sign up message$/ do
page.should have_content "Welcome! You have signed up successfully."
end

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
fill_in(field, :with => value)
Then /^I should see an invalid email message$/ do
page.should have_content "Email is invalid"
end

When /^I go to the homepage$/ do
visit '/'
Then /^I should see a missing password message$/ do
page.should have_content "Password can't be blank"
end

Then /^I should see a missing password confirmation message$/ do
page.should have_content "Password doesn't match confirmation"
end

Then /^I should see a mismatched password message$/ do
page.should have_content "Password doesn't match confirmation"
end

Then /^I should see a signed out message$/ do
page.should have_content "Signed out"
end

Then /^I see an invalid login message$/ do
page.should have_content "Invalid email or password."
end

Then /^I see a successfull sign in message$/ do
page.should have_content "Signed in successfully."
end

Then /^I should see an account edited message$/ do
page.should have_content "You updated your account successfully."
end

When /^I follow "([^"]*)"$/ do |text|
click_link text
Then /^I should see my name$/ do
page.should have_content valid_user[:name]
end
37 changes: 15 additions & 22 deletions features/users/sign_in.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,22 @@ Feature: Sign in
Should be able to sign in

Scenario: User is not signed up
Given I am not logged in
And no user exists with an email of "user@test.com"
When I go to the sign in page
And I sign in as "user@test.com/please"
Then I should see "Invalid email or password."
And I go to the home page
And I should be signed out
Given I do not exist as a user
When I sign in with valid credintials
Then I see an invalid login message
And I should be signed out

Scenario: User enters wrong password
Given I am not logged in
And I am a user named "foo" with an email "user@test.com" and password "please"
When I go to the sign in page
And I sign in as "user@test.com/wrongpassword"
Then I should see "Invalid email or password."
And I go to the home page
And I should be signed out
Given I exist as a user
And I am not logged in
When I sign in with a wrong password
Then I see an invalid login message
And I should be signed out

Scenario: User signs in successfully with email
Given I am not logged in
And I am a user named "foo" with an email "user@test.com" and password "please"
When I go to the sign in page
And I sign in as "user@test.com/please"
Then I should see "Signed in successfully."
And I should be signed in
When I return next time
Then I should be already signed in
Given I exist as a user
And I am not logged in
When I sign in with valid credintials
Then I see a successfull sign in message
When I return to the site
Then I should be signed in
10 changes: 4 additions & 6 deletions features/users/sign_out.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ Feature: Sign out
Should be able to sign out

Scenario: User signs out
Given I am a user named "foo" with an email "user@test.com" and password "please"
When I sign in as "user@test.com/please"
Then I should be signed in
And I sign out
Then I should see "Signed out"
When I return next time
Given I am logged in
When I sign out
Then I should see a signed out message
When I return to the site
Then I should be signed out
47 changes: 10 additions & 37 deletions features/users/sign_up.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,24 @@ Feature: Sign up

Background:
Given I am not logged in
And I am on the home page
And I go to the sign up page

Scenario: User signs up with valid data
And I fill in the following:
| Name | Testy McUserton |
| Email | user@test.com |
| Password | please |
| Password confirmation | please |
And I press "Sign up"
Then I should see "Welcome! You have signed up successfully."
When I sign up with valid user data
Then I should see a succesfull sign up message

Scenario: User signs up with invalid email
And I fill in the following:
| Name | Testy McUserton |
| Email | invalidemail |
| Password | please |
| Password confirmation | please |
And I press "Sign up"
Then I should see "Email is invalid"
When I sign up with an invalid email
Then I should see an invalid email message

Scenario: User signs up without password
And I fill in the following:
| Name | Testy McUserton |
| Email | user@test.com |
| Password | |
| Password confirmation | please |
And I press "Sign up"
Then I should see "Password can't be blank"
When I sign up without a password
Then I should see a missing password message

Scenario: User signs up without password confirmation
And I fill in the following:
| Name | Testy McUserton |
| Email | user@test.com |
| Password | please |
| Password confirmation | |
And I press "Sign up"
Then I should see "Password doesn't match confirmation"
When I sign up without a confirmed password
Then I should see a missing password confirmation message

Scenario: User signs up with mismatched password and confirmation
And I fill in the following:
| Name | Testy McUserton |
| Email | user@test.com |
| Password | please |
| Password confirmation | please1 |
And I press "Sign up"
Then I should see "Password doesn't match confirmation"
When I sign up with a mismatched password confirmation
Then I should see a mismatched password message

12 changes: 3 additions & 9 deletions features/users/user_edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ Feature: Edit User
so I can change my username

Scenario: I sign in and edit my account
Given I am a user named "foo" with an email "user@test.com" and password "please"
When I sign in as "user@test.com/please"
Then I should be signed in
When I follow "Edit account"
And I fill in "Name" with "baz"
And I fill in "Current password" with "please"
And I press "Update"
And I go to the homepage
Then I should see "User: baz"
Given I am logged in
When I edit my account details
Then I should see an account edited message
6 changes: 3 additions & 3 deletions features/users/user_show.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Feature: Show Users
so I can know if the site has users

Scenario: Viewing users
Given I am a user named "foo" with an email "user@test.com" and password "please"
When I go to the homepage
Then I should see "User: foo"
Given I exist as a user
When I look at the list of users
Then I should see my name