forked from otwcode/otwarchive
/
user_steps.rb
121 lines (102 loc) · 3.05 KB
/
user_steps.rb
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
117
118
119
120
121
DEFAULT_USER = "testuser"
DEFAULT_PASSWORD = "password"
Given /^I have no users$/ do
User.delete_all
end
Given /I have an orphan account/ do
user = Factory.create(:user, :login => 'orphan_account')
user.activate
end
Given /the following activated users? exists?/ do |table|
table.hashes.each do |hash|
user = Factory.create(:user, hash)
user.activate
end
end
Given /the following activated tag wranglers? exists?/ do |table|
table.hashes.each do |hash|
user = Factory.create(:user, hash)
user.activate
user.tag_wrangler = '1'
end
end
Given /^I am logged in as "([^\"]*)" with password "([^\"]*)"$/ do |login, password|
Given "I am logged out"
user = User.find_by_login(login)
if user.blank?
user = Factory.create(:user, {:login => login, :password => password})
user.activate
else
user.password = password
user.password_confirmation = password
user.save
end
visit login_path
fill_in "User name", :with => login
fill_in "Password", :with => password
check "Remember me"
click_button "Log in"
assert UserSession.find
end
Given /^I am logged in as "([^\"]*)"$/ do |login|
Given %{I am logged in as "#{login}" with password "#{DEFAULT_PASSWORD}"}
end
Given /^I am logged in$/ do
Given %{I am logged in as "#{DEFAULT_USER}"}
end
When /^I fill in "([^\"]*)"'s temporary password$/ do |login|
# " '
user = User.find_by_login(login)
fill_in "Password", :with => user.activation_code
end
Given /^I am logged in as a random user$/ do
Given "I am logged out"
name = "testuser#{User.count + 1}"
user = Factory.create(:user, :login => name, :password => DEFAULT_PASSWORD)
user.activate
visit login_path
fill_in "User name", :with => name
fill_in "Password", :with => DEFAULT_PASSWORD
check "Remember me"
click_button "Log in"
assert UserSession.find
end
Given /^I am logged out$/ do
visit logout_path
assert !UserSession.find
visit admin_logout_path
assert !AdminSession.find
end
Given /^I log out$/ do
Given %{I follow "log out"}
end
When /^"([^\"]*)" creates the pseud "([^\"]*)"$/ do |username, newpseud|
visit user_pseuds_path(username)
click_link("New Pseud")
fill_in "Name", :with => newpseud
click_button "Create"
end
Given /^"([^\"]*)" has the pseud "([^\"]*)"$/ do |username, pseud|
When %{I am logged in as "#{username}"}
When %{"#{username}" creates the pseud "#{pseud}"}
When "I am logged out"
end
When /^"([^\"]*)" creates the default pseud "([^\"]*)"$/ do |username, newpseud|
visit user_pseuds_path(username)
click_link("New Pseud")
fill_in "Name", :with => newpseud
# TODO: this isn't currently working
check "Make this name default"
click_button "Create"
end
Given /^"([^\"]*)" deletes their account/ do |username|
visit user_path(username)
Given %{I follow "Profile"}
Given %{I follow "Delete My Account"}
end
Given /^I am a visitor$/ do
Given %{I am logged out}
end
Then /^I should get the error message for wrong username or password$/ do
Then %{I should see "The password or user name you entered doesn't match our records. Please try again"}
end