clearance_steps.rb
3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# General
Then /^I should see error messages$/ do
assert_match /error(s)? prohibited/m, response.body
end
# Database
Given /^no user exists with an email of "(.*)"$/ do |email|
assert_nil User.find_by_email(email)
end
Given /^I signed up with "(.*)\/(.*)"$/ do |email, password|
user = Factory :user,
:email => email,
:password => password,
:password_confirmation => password
end
Given /^I am signed up and confirmed as "(.*)\/(.*)"$/ do |email, password|
user = Factory :email_confirmed_user,
:email => email,
:password => password,
:password_confirmation => password
end
# Session
Then /^I should be signed in$/ do
assert controller.signed_in?
end
Then /^I should be signed out$/ do
assert ! controller.signed_in?
end
When /^session is cleared$/ do
request.reset_session
controller.instance_variable_set(:@_current_user, nil)
end
Given /^I have signed in with "(.*)\/(.*)"$/ do |email, password|
Given %{I am signed up and confirmed as "#{email}/#{password}"}
And %{I sign in as "#{email}/#{password}"}
end
# Emails
Then /^a confirmation message should be sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
sent = ActionMailer::Base.deliveries.first
assert_equal [user.email], sent.to
assert_match /confirm/i, sent.subject
assert !user.confirmation_token.blank?
assert_match /#{user.confirmation_token}/, sent.body
end
When /^I follow the confirmation link sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
visit new_user_confirmation_path(:user_id => user,
:token => user.confirmation_token)
end
Then /^a password reset message should be sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
sent = ActionMailer::Base.deliveries.first
assert_equal [user.email], sent.to
assert_match /password/i, sent.subject
assert !user.confirmation_token.blank?
assert_match /#{user.confirmation_token}/, sent.body
end
When /^I follow the password reset link sent to "(.*)"$/ do |email|
user = User.find_by_email(email)
visit edit_user_password_path(:user_id => user,
:token => user.confirmation_token)
end
When /^I try to change the password of "(.*)" without token$/ do |email|
user = User.find_by_email(email)
visit edit_user_password_path(:user_id => user)
end
Then /^I should be forbidden$/ do
assert_response :forbidden
end
# Actions
When /^I sign in as "(.*)\/(.*)"$/ do |email, password|
When %{I go to the sign in page}
And %{I fill in "Email" with "#{email}"}
And %{I fill in "Password" with "#{password}"}
And %{I press "Sign In"}
end
When /^I sign out$/ do
visit '/session', :delete
end
When /^I request password reset link to be sent to "(.*)"$/ do |email|
When %{I go to the password reset request page}
And %{I fill in "Email" with "#{email}"}
And %{I press "Reset password"}
end
When /^I update my password with "(.*)\/(.*)"$/ do |password, confirmation|
And %{I fill in "Password" with "#{password}"}
And %{I fill in "Password confirmation" with "#{confirmation}"}
And %{I press "Save this password"}
end
When /^I return next time$/ do
When %{session is cleared}
And %{I go to the homepage}
end