Skip to content

Commit 1ea4959

Browse files
committed
update Cucumber features and steps top accommodate Devise confirmable
1 parent 5d60771 commit 1ea4959

File tree

4 files changed

+111
-57
lines changed

4 files changed

+111
-57
lines changed
Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
11
### UTILITY METHODS ###
2-
def valid_user
3-
@user ||= { :name => "Testy McUserton", :email => "testy@userton.com",
4-
:password => "please", :password_confirmation => "please"}
2+
3+
def create_visitor
4+
@visitor ||= { :name => "Testy McUserton", :email => "example@example.com",
5+
:password => "please", :password_confirmation => "please" }
6+
end
7+
8+
def find_user
9+
@user ||= User.first conditions: {:email => @visitor[:email]}
10+
end
11+
12+
def create_unconfirmed_user
13+
create_visitor
14+
delete_user
15+
sign_up
16+
visit '/users/sign_out'
17+
end
18+
19+
def create_user
20+
create_visitor
21+
delete_user
22+
@user = FactoryGirl.create(:user, email: @visitor[:email])
523
end
624

7-
def sign_up user
25+
def delete_user
26+
@user ||= User.first conditions: {:email => @visitor[:email]}
27+
@user.destroy unless @user.nil?
28+
end
29+
30+
def sign_up
31+
delete_user
832
visit '/users/sign_up'
9-
fill_in "Name", :with => user[:name]
10-
fill_in "Email", :with => user[:email]
11-
fill_in "Password", :with => user[:password]
12-
fill_in "Password confirmation", :with => user[:password_confirmation]
33+
fill_in "Name", :with => @visitor[:name]
34+
fill_in "Email", :with => @visitor[:email]
35+
fill_in "Password", :with => @visitor[:password]
36+
fill_in "Password confirmation", :with => @visitor[:password_confirmation]
1337
click_button "Sign up"
38+
find_user
1439
end
1540

16-
def sign_in user
41+
def sign_in
1742
visit '/users/sign_in'
18-
fill_in "Email", :with => user[:email]
19-
fill_in "Password", :with => user[:password]
43+
fill_in "Email", :with => @visitor[:email]
44+
fill_in "Password", :with => @visitor[:password]
2045
click_button "Sign in"
2146
end
2247

@@ -26,65 +51,80 @@ def sign_in user
2651
end
2752

2853
Given /^I am logged in$/ do
29-
sign_up valid_user
54+
create_user
55+
sign_in
3056
end
3157

3258
Given /^I exist as a user$/ do
33-
sign_up valid_user
34-
visit '/users/sign_out'
59+
create_user
3560
end
3661

3762
Given /^I do not exist as a user$/ do
38-
User.find(:first, :conditions => { :email => valid_user[:email] }).should be_nil
39-
visit '/users/sign_out'
63+
create_visitor
64+
delete_user
65+
end
66+
67+
Given /^I exist as an unconfirmed user$/ do
68+
create_unconfirmed_user
4069
end
4170

4271
### WHEN ###
72+
When /^I sign in with valid credentials$/ do
73+
create_visitor
74+
sign_in
75+
end
76+
4377
When /^I sign out$/ do
4478
visit '/users/sign_out'
4579
end
4680

4781
When /^I sign up with valid user data$/ do
48-
sign_up valid_user
82+
create_visitor
83+
sign_up
4984
end
5085

5186
When /^I sign up with an invalid email$/ do
52-
user = valid_user.merge(:email => "notanemail")
53-
sign_up user
87+
create_visitor
88+
@visitor = @visitor.merge(:email => "notanemail")
89+
sign_up
5490
end
5591

56-
When /^I sign up without a confirmed password$/ do
57-
user = valid_user.merge(:password_confirmation => "")
58-
sign_up user
92+
When /^I sign up without a password confirmation$/ do
93+
create_visitor
94+
@visitor = @visitor.merge(:password_confirmation => "")
95+
sign_up
5996
end
6097

6198
When /^I sign up without a password$/ do
62-
user = valid_user.merge(:password => "")
63-
sign_up user
99+
create_visitor
100+
@visitor = @visitor.merge(:password => "")
101+
sign_up
64102
end
65103

66104
When /^I sign up with a mismatched password confirmation$/ do
67-
user = valid_user.merge(:password_confirmation => "please123")
68-
sign_up user
105+
create_visitor
106+
@visitor = @visitor.merge(:password_confirmation => "please123")
107+
sign_up
69108
end
70109

71110
When /^I return to the site$/ do
72111
visit '/'
73112
end
74113

75-
When /^I sign in with a wrong password$/ do
76-
user = valid_user.merge(:password => "wrongpass")
77-
sign_in user
114+
When /^I sign in with a wrong email$/ do
115+
@visitor = @visitor.merge(:email => "wrong@example.com")
116+
sign_in
78117
end
79118

80-
When /^I sign in with valid credentials$/ do
81-
sign_in valid_user
119+
When /^I sign in with a wrong password$/ do
120+
@visitor = @visitor.merge(:password => "wrongpass")
121+
sign_in
82122
end
83123

84124
When /^I edit my account details$/ do
85125
click_link "Edit account"
86126
fill_in "Name", :with => "newname"
87-
fill_in "Current password", :with => valid_user[:password]
127+
fill_in "Current password", :with => @visitor[:password]
88128
click_button "Update"
89129
end
90130

@@ -105,8 +145,16 @@ def sign_in user
105145
page.should_not have_content "Logout"
106146
end
107147

148+
Then /^I see an unconfirmed account message$/ do
149+
page.should have_content "You have to confirm your account before continuing."
150+
end
151+
152+
Then /^I see a successful sign in message$/ do
153+
page.should have_content "Signed in successfully."
154+
end
155+
108156
Then /^I should see a successful sign up message$/ do
109-
page.should have_content "Welcome! You have signed up successfully."
157+
page.should have_content "A message with a confirmation link has been sent to your email address."
110158
end
111159

112160
Then /^I should see an invalid email message$/ do
@@ -126,21 +174,18 @@ def sign_in user
126174
end
127175

128176
Then /^I should see a signed out message$/ do
129-
page.should have_content "Signed out"
177+
page.should have_content "Signed out successfully."
130178
end
131179

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

136-
Then /^I see a successful sign in message$/ do
137-
page.should have_content "Signed in successfully."
138-
end
139-
140184
Then /^I should see an account edited message$/ do
141185
page.should have_content "You updated your account successfully."
142186
end
143187

144188
Then /^I should see my name$/ do
145-
page.should have_content valid_user[:name]
189+
create_user
190+
page.should have_content @user[:name]
146191
end

features/users/sign_in.feature

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@ Feature: Sign in
99
Then I see an invalid login message
1010
And I should be signed out
1111

12-
Scenario: User enters wrong password
13-
Given I exist as a user
14-
And I am not logged in
15-
When I sign in with a wrong password
16-
Then I see an invalid login message
17-
And I should be signed out
18-
19-
Scenario: User signs in successfully with email
12+
Scenario: User signs in successfully
2013
Given I exist as a user
2114
And I am not logged in
2215
When I sign in with valid credentials
2316
Then I see a successful sign in message
2417
When I return to the site
2518
Then I should be signed in
19+
20+
Scenario: User enters wrong email
21+
Given I exist as a user
22+
And I am not logged in
23+
When I sign in with a wrong email
24+
Then I see an invalid login message
25+
And I should be signed out
26+
27+
Scenario: User enters wrong password
28+
Given I exist as a user
29+
And I am not logged in
30+
When I sign in with a wrong password
31+
Then I see an invalid login message
32+
And I should be signed out
33+
34+

features/users/sign_up.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ Feature: Sign up
1919
Then I should see a missing password message
2020

2121
Scenario: User signs up without password confirmation
22-
When I sign up without a confirmed password
22+
When I sign up without a password confirmation
2323
Then I should see a missing password confirmation message
2424

2525
Scenario: User signs up with mismatched password and confirmation
2626
When I sign up with a mismatched password confirmation
2727
Then I should see a mismatched password message
28-

spec/factories.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
require 'factory_girl'
2-
3-
Factory.define :user do |u|
4-
u.name 'Test User'
5-
u.email 'user@test.com'
6-
u.password 'please'
7-
end
8-
1+
FactoryGirl.define do
2+
factory :user do
3+
name 'Test User'
4+
email 'example@example.com'
5+
password 'please'
6+
password_confirmation 'please'
7+
confirmed_at Time.now unless Devise::Models::Confirmable.nil?
8+
end
9+
end

0 commit comments

Comments
 (0)