headstart 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +117 -0
- data/Rakefile +95 -0
- data/VERSION +1 -0
- data/app/controllers/headstart/confirmations_controller.rb +76 -0
- data/app/controllers/headstart/impersonations_controller.rb +44 -0
- data/app/controllers/headstart/passwords_controller.rb +93 -0
- data/app/controllers/headstart/sessions_controller.rb +76 -0
- data/app/controllers/headstart/users_controller.rb +85 -0
- data/app/models/deliver_change_password_job.rb +19 -0
- data/app/models/deliver_welcome_job.rb +17 -0
- data/app/models/generic_mailer.rb +31 -0
- data/app/models/headstart_mailer.rb +28 -0
- data/app/models/impersonation.rb +26 -0
- data/app/models/mimi_mailer.rb +30 -0
- data/app/views/generic_mailer/change_password.html.erb +9 -0
- data/app/views/generic_mailer/confirmation.html.erb +5 -0
- data/app/views/generic_mailer/welcome.html.erb +1 -0
- data/app/views/impersonations/index.html.erb +5 -0
- data/app/views/passwords/edit.html.erb +23 -0
- data/app/views/passwords/new.html.erb +15 -0
- data/app/views/sessions/new.html.erb +48 -0
- data/app/views/users/_form.html.erb +21 -0
- data/app/views/users/edit.html.erb +6 -0
- data/app/views/users/new.html.erb +6 -0
- data/app/views/users/show.html.erb +8 -0
- data/generators/headstart/USAGE +1 -0
- data/generators/headstart/headstart_generator.rb +86 -0
- data/generators/headstart/lib/insert_commands.rb +33 -0
- data/generators/headstart/lib/rake_commands.rb +22 -0
- data/generators/headstart/templates/README +20 -0
- data/generators/headstart/templates/app/controllers/sessions_controller.rb +6 -0
- data/generators/headstart/templates/app/views/sessions/index.html.erb +1 -0
- data/generators/headstart/templates/application.html.erb +75 -0
- data/generators/headstart/templates/factories.rb +23 -0
- data/generators/headstart/templates/headstart.rb +25 -0
- data/generators/headstart/templates/headstart.yml +45 -0
- data/generators/headstart/templates/layout.css +353 -0
- data/generators/headstart/templates/migrations/create_users.rb +26 -0
- data/generators/headstart/templates/migrations/update_users.rb +44 -0
- data/generators/headstart/templates/report.css +69 -0
- data/generators/headstart/templates/reset.css +1 -0
- data/generators/headstart/templates/style.css +31 -0
- data/generators/headstart/templates/text.css +1 -0
- data/generators/headstart/templates/user.rb +3 -0
- data/generators/headstart/templates/xd_receiver.html +10 -0
- data/generators/headstart/templates/xd_receiver_ssl.html +10 -0
- data/generators/headstart_admin/USAGE +1 -0
- data/generators/headstart_admin/headstart_admin_generator.rb +32 -0
- data/generators/headstart_admin/lib/insert_commands.rb +33 -0
- data/generators/headstart_admin/templates/README +16 -0
- data/generators/headstart_admin/templates/app/controllers/admin/admin_controller.rb +17 -0
- data/generators/headstart_admin/templates/app/controllers/admin/users_controller.rb +52 -0
- data/generators/headstart_admin/templates/app/views/admin/admin/index.html.erb +2 -0
- data/generators/headstart_admin/templates/app/views/admin/users/_form.html.erb +25 -0
- data/generators/headstart_admin/templates/app/views/admin/users/edit.html.erb +6 -0
- data/generators/headstart_admin/templates/app/views/admin/users/index.html.erb +7 -0
- data/generators/headstart_admin/templates/app/views/admin/users/new.html.erb +6 -0
- data/generators/headstart_admin/templates/app/views/admin/users/show.html.erb +10 -0
- data/generators/headstart_admin/templates/test/integration/admin/users_test.rb +201 -0
- data/generators/headstart_tests/USAGE +1 -0
- data/generators/headstart_tests/headstart_tests_generator.rb +21 -0
- data/generators/headstart_tests/templates/README +58 -0
- data/generators/headstart_tests/templates/test/integration/edit_profile_test.rb +35 -0
- data/generators/headstart_tests/templates/test/integration/facebook_test.rb +61 -0
- data/generators/headstart_tests/templates/test/integration/impersonation_test.rb +39 -0
- data/generators/headstart_tests/templates/test/integration/password_reset_test.rb +128 -0
- data/generators/headstart_tests/templates/test/integration/sign_in_test.rb +66 -0
- data/generators/headstart_tests/templates/test/integration/sign_out_test.rb +28 -0
- data/generators/headstart_tests/templates/test/integration/sign_up_test.rb +47 -0
- data/lib/headstart/authentication.rb +138 -0
- data/lib/headstart/configuration.rb +34 -0
- data/lib/headstart/extensions/errors.rb +6 -0
- data/lib/headstart/extensions/rescue.rb +5 -0
- data/lib/headstart/routes.rb +67 -0
- data/lib/headstart/user.rb +279 -0
- data/lib/headstart.rb +7 -0
- data/rails/init.rb +4 -0
- data/shoulda_macros/headstart.rb +244 -0
- data/test/controllers/passwords_controller_test.rb +184 -0
- data/test/controllers/sessions_controller_test.rb +129 -0
- data/test/controllers/users_controller_test.rb +57 -0
- data/test/models/headstart_mailer_test.rb +52 -0
- data/test/models/impersonation_test.rb +25 -0
- data/test/models/user_test.rb +213 -0
- data/test/rails_root/app/controllers/accounts_controller.rb +10 -0
- data/test/rails_root/app/controllers/application_controller.rb +6 -0
- data/test/rails_root/app/helpers/application_helper.rb +5 -0
- data/test/rails_root/app/helpers/confirmations_helper.rb +2 -0
- data/test/rails_root/app/helpers/passwords_helper.rb +2 -0
- data/test/rails_root/config/boot.rb +110 -0
- data/test/rails_root/config/environment.rb +22 -0
- data/test/rails_root/config/environments/development.rb +19 -0
- data/test/rails_root/config/environments/production.rb +1 -0
- data/test/rails_root/config/environments/test.rb +37 -0
- data/test/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails_root/config/initializers/requires.rb +13 -0
- data/test/rails_root/config/initializers/time_formats.rb +4 -0
- data/test/rails_root/config/routes.rb +9 -0
- data/test/rails_root/public/dispatch.rb +10 -0
- data/test/rails_root/script/create_project.rb +52 -0
- data/test/rails_root/test/functional/accounts_controller_test.rb +23 -0
- data/test/test_helper.rb +21 -0
- metadata +232 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
class Admin::UsersController < Admin::AdminController
|
|
2
|
+
|
|
3
|
+
def index
|
|
4
|
+
@users = User.all
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def show
|
|
8
|
+
@user = User.find(params[:id])
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@user = User.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
@user = User.new(params[:user])
|
|
17
|
+
@user.role = params[:user][:role]
|
|
18
|
+
if @user.save
|
|
19
|
+
flash[:notice] = "Created #{@user.name}"
|
|
20
|
+
redirect_to admin_user_url(@user)
|
|
21
|
+
else
|
|
22
|
+
render :action => 'new'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def edit
|
|
27
|
+
@user = User.find(params[:id])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def update
|
|
31
|
+
@user = User.find(params[:id])
|
|
32
|
+
@user.role = params[:user][:role]
|
|
33
|
+
if @user.update_attributes(params[:user])
|
|
34
|
+
flash[:notice] = "Updated #{@user.name}"
|
|
35
|
+
redirect_to admin_user_url(@user)
|
|
36
|
+
else
|
|
37
|
+
render :action => 'edit'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def destroy
|
|
42
|
+
@user = User.find(params[:id])
|
|
43
|
+
if @user != current_user
|
|
44
|
+
@user.destroy
|
|
45
|
+
flash[:notice] = "Deleted #{@user.name}"
|
|
46
|
+
else
|
|
47
|
+
flash[:error] = "Cannot delete yourself"
|
|
48
|
+
end
|
|
49
|
+
redirect_to admin_users_url
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<%= form.error_messages %>
|
|
2
|
+
<p class="text_field">
|
|
3
|
+
<%= form.label :first_name %>
|
|
4
|
+
<%= form.text_field :first_name %>
|
|
5
|
+
</p>
|
|
6
|
+
<p class="text_field">
|
|
7
|
+
<%= form.label :last_name %>
|
|
8
|
+
<%= form.text_field :last_name %>
|
|
9
|
+
</p>
|
|
10
|
+
<p class="text_field">
|
|
11
|
+
<%= form.label :email %>
|
|
12
|
+
<%= form.text_field :email %>
|
|
13
|
+
</p>
|
|
14
|
+
<p class="password_field">
|
|
15
|
+
<%= form.label :password %>
|
|
16
|
+
<%= form.password_field :password %>
|
|
17
|
+
</p>
|
|
18
|
+
<p class="password_field">
|
|
19
|
+
<%= form.label :password_confirmation, "Confirm password" %>
|
|
20
|
+
<%= form.password_field :password_confirmation %>
|
|
21
|
+
</p>
|
|
22
|
+
<p>
|
|
23
|
+
<%= form.label :role %>
|
|
24
|
+
<%= form.collection_select :role, ['', 'admin'], :to_s, :to_s %>
|
|
25
|
+
</p>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<h2>User Details</h2>
|
|
2
|
+
|
|
3
|
+
<div id="user_profile">
|
|
4
|
+
<b>First Name:</b> <%=h @user.first_name %><br/>
|
|
5
|
+
<b>Last Name:</b> <%=h @user.last_name %><br/>
|
|
6
|
+
<b>Email:</b> <%=h @user.email %><br/>
|
|
7
|
+
<%= link_to 'Edit', edit_admin_user_path(@user) %><br/>
|
|
8
|
+
<%= link_to 'Delete', admin_user_path(@user), :method => :delete, :confirm => 'Are you sure?' %><br/>
|
|
9
|
+
<%= link_to 'Impersonate', impersonation_path(:user_id => @user.id), :method => :post, :id => "impersonate_#{@user.id}" %>
|
|
10
|
+
</div>
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/../../test_helper"
|
|
2
|
+
|
|
3
|
+
class Admin::UsersTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
setup do
|
|
6
|
+
ActionMailer::Base.deliveries.clear
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
teardown do
|
|
10
|
+
ActionMailer::Base.deliveries.clear
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context 'Signed in as an admin' do
|
|
14
|
+
|
|
15
|
+
setup do
|
|
16
|
+
@bob = Factory(:user, :email => 'bob@bob.bob', :first_name => 'Bob')
|
|
17
|
+
@joe = Factory(:user, :email => 'joe@joe.joe', :first_name => 'Joe')
|
|
18
|
+
@ted = Factory(:user, :email => 'ted@ted.ted', :first_name => 'Ted')
|
|
19
|
+
@admin_user = Factory(:admin_user, :email => 'admin@example.com')
|
|
20
|
+
sign_in_as(@admin_user.email, @admin_user.password)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'when listing users' do
|
|
24
|
+
|
|
25
|
+
should 'show the list of users' do
|
|
26
|
+
visit admin_users_url
|
|
27
|
+
assert_contain(/bob@bob.bob/)
|
|
28
|
+
assert_contain(/joe@joe.joe/)
|
|
29
|
+
assert_contain(/ted@ted.ted/)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'when creating a new user' do
|
|
35
|
+
|
|
36
|
+
context 'with valid data' do
|
|
37
|
+
|
|
38
|
+
should 'display "Created [name]"' do
|
|
39
|
+
create_user(:first_name => 'Tom', :last_name => 'Tom')
|
|
40
|
+
assert_contain(/Created Tom Tom/)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
should 'redirect to the user show page' do
|
|
44
|
+
create_user(:email => 'tom@tom.tom')
|
|
45
|
+
user = User.find_by_email('tom@tom.tom')
|
|
46
|
+
assert_equal current_url, admin_user_url(user)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
should 'be able to set the role' do
|
|
50
|
+
create_user(:email => 'tom@tom.tom', :role => 'admin')
|
|
51
|
+
user = User.find_by_email('tom@tom.tom')
|
|
52
|
+
assert user.admin?
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context 'with invalid data' do
|
|
58
|
+
|
|
59
|
+
should 'display error messages' do
|
|
60
|
+
create_user(
|
|
61
|
+
:first_name => '',
|
|
62
|
+
:last_name => '',
|
|
63
|
+
:email => 'invalidemail',
|
|
64
|
+
:password_confirmation => 'bad')
|
|
65
|
+
assert_contain(/First name can't be blank/)
|
|
66
|
+
assert_contain(/Last name can't be blank/)
|
|
67
|
+
assert_contain(/Email is invalid/)
|
|
68
|
+
assert_contain(/Password doesn't match confirmation/)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
should 'redisplay the new user form' do
|
|
72
|
+
create_user(:first_name => '')
|
|
73
|
+
assert_have_selector 'form.new_user'
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context 'when editing a user' do
|
|
81
|
+
|
|
82
|
+
context 'with valid data' do
|
|
83
|
+
|
|
84
|
+
should 'display "Updated [name]"' do
|
|
85
|
+
edit_user(@ted, :first_name => 'Tom', :last_name => 'Tom' )
|
|
86
|
+
assert_contain(/Updated Tom Tom/)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should 'redirect to the user show page' do
|
|
90
|
+
edit_user(@ted, :email => 'tom@tom.tom')
|
|
91
|
+
user = User.find_by_email('tom@tom.tom')
|
|
92
|
+
assert_equal current_url, admin_user_url(user)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
should 'be able to change the role' do
|
|
96
|
+
edit_user(@ted, :role => 'admin')
|
|
97
|
+
@ted.reload
|
|
98
|
+
assert @ted.admin?
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context 'with invalid data' do
|
|
104
|
+
|
|
105
|
+
should 'display error messages' do
|
|
106
|
+
edit_user(@ted,
|
|
107
|
+
:first_name => '',
|
|
108
|
+
:last_name => '',
|
|
109
|
+
:email => 'invalidemail',
|
|
110
|
+
:password => 'good',
|
|
111
|
+
:password_confirmation => 'bad')
|
|
112
|
+
assert_contain(/First name can't be blank/)
|
|
113
|
+
assert_contain(/Last name can't be blank/)
|
|
114
|
+
assert_contain(/Email is invalid/)
|
|
115
|
+
assert_contain(/Password doesn't match confirmation/)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
should 'redisplay the edit form' do
|
|
119
|
+
edit_user(@ted, :first_name => '')
|
|
120
|
+
assert_have_selector 'form.edit_user'
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context 'when deleting a user' do
|
|
128
|
+
|
|
129
|
+
should 'display "Deleted [name]"' do
|
|
130
|
+
delete_user(@bob)
|
|
131
|
+
assert_contain(/Deleted Bob/)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
should 'redirect to the user list' do
|
|
135
|
+
delete_user(@bob)
|
|
136
|
+
assert_equal current_url, admin_users_url
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
should 'not display the deleted user in the list' do
|
|
140
|
+
delete_user(@bob)
|
|
141
|
+
assert_not_contain(/bob@bob.bob/)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
should 'not allow deleting currently logged in user' do
|
|
145
|
+
visit admin_user_url(@admin_user), :delete
|
|
146
|
+
assert_contain(/Cannot delete yourself/)
|
|
147
|
+
assert_contain(/admin@example.com/)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
context 'Signed in as a non-admin user' do
|
|
155
|
+
|
|
156
|
+
setup do
|
|
157
|
+
@user = Factory(:user)
|
|
158
|
+
sign_in_as(@user.email, @user.password)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
should 'not give access' do
|
|
162
|
+
visit admin_users_url
|
|
163
|
+
assert_not_equal current_url, admin_users_url
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
private
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def create_user(options = {})
|
|
173
|
+
visit admin_users_url
|
|
174
|
+
click_link 'New User'
|
|
175
|
+
fill_in 'Email', :with => options[:email] || 'tom@tom.tom'
|
|
176
|
+
fill_in 'Password', :with => options[:password] || 'password'
|
|
177
|
+
fill_in 'Confirm Password', :with => options[:password_confirmation] || options[:password] || 'password'
|
|
178
|
+
fill_in 'First Name', :with => options[:first_name] || 'Tom'
|
|
179
|
+
fill_in 'Last Name', :with => options[:last_name] || 'Tom'
|
|
180
|
+
select options[:role] || '', :from => 'Role'
|
|
181
|
+
click_button 'Save'
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def edit_user(user, options = {})
|
|
185
|
+
visit admin_user_url(user)
|
|
186
|
+
click_link 'Edit'
|
|
187
|
+
fill_in 'Email', :with => options[:email] || 'tom@tom.tom'
|
|
188
|
+
fill_in 'Password', :with => options[:password] || ''
|
|
189
|
+
fill_in 'Confirm Password', :with => options[:password_confirmation] || options[:password] || ''
|
|
190
|
+
fill_in 'First Name', :with => options[:first_name] || 'Tom'
|
|
191
|
+
fill_in 'Last Name', :with => options[:last_name] || 'Tom'
|
|
192
|
+
select options[:role] || '', :from => 'Role'
|
|
193
|
+
click_button 'Save'
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def delete_user(user)
|
|
197
|
+
visit admin_user_url(user)
|
|
198
|
+
click_link 'Delete'
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
script/generate headstart_tests
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class HeadstartTestsGenerator < Rails::Generator::Base
|
|
2
|
+
|
|
3
|
+
def manifest
|
|
4
|
+
record do |m|
|
|
5
|
+
m.directory File.join("test", "integration")
|
|
6
|
+
|
|
7
|
+
["test/integration/facebook_test.rb",
|
|
8
|
+
"test/integration/impersonation_test.rb",
|
|
9
|
+
"test/integration/sign_in_test.rb",
|
|
10
|
+
"test/integration/sign_out_test.rb",
|
|
11
|
+
"test/integration/sign_up_test.rb",
|
|
12
|
+
"test/integration/edit_profile_test.rb",
|
|
13
|
+
"test/integration/password_reset_test.rb"].each do |file|
|
|
14
|
+
m.file file, file
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
m.readme "README"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
*******************************************************************************
|
|
3
|
+
|
|
4
|
+
Next:
|
|
5
|
+
|
|
6
|
+
1. To run the generated tests, you'll need shoulda, factory_girl, webrat, and fakeweb.
|
|
7
|
+
Update your config/environments/test.rb:
|
|
8
|
+
|
|
9
|
+
config.gem "shoulda"
|
|
10
|
+
config.gem "factory_girl"
|
|
11
|
+
config.gem "webrat"
|
|
12
|
+
config.gem "fakeweb"
|
|
13
|
+
|
|
14
|
+
Unless they are already included.
|
|
15
|
+
|
|
16
|
+
2. Update your test_helper.rb with:
|
|
17
|
+
|
|
18
|
+
FakeWeb.allow_net_connect = false
|
|
19
|
+
|
|
20
|
+
Webrat.configure do |config|
|
|
21
|
+
config.mode = :rails
|
|
22
|
+
config.open_error_files = false
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class ActionController::IntegrationTest
|
|
26
|
+
include Webrat::Matchers
|
|
27
|
+
|
|
28
|
+
def sign_in_as(email, password, url_to_visit = sign_in_url)
|
|
29
|
+
visit url_to_visit
|
|
30
|
+
fill_in "Email", :with => email
|
|
31
|
+
fill_in "Password", :with => password
|
|
32
|
+
click_button "sign in"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def reset_session
|
|
36
|
+
request.reset_session
|
|
37
|
+
controller.instance_variable_set(:@_current_user, nil)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def sign_up(options = {})
|
|
41
|
+
visit new_user_url
|
|
42
|
+
fill_in "email", :with => options[:email] || 'bob@bob.bob'
|
|
43
|
+
fill_in "first name", :with => options[:first_name] || 'Bob'
|
|
44
|
+
fill_in "last name", :with => options[:last_name] || 'Bob'
|
|
45
|
+
fill_in "password", :with => options[:password] || 'password'
|
|
46
|
+
fill_in "confirm password", :with => options[:password_confirmation] || options[:password] || 'password'
|
|
47
|
+
click_button 'sign up'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def sign_out
|
|
51
|
+
visit session_url, :delete
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
3. Be sure to define a root_url in routes.rb.
|
|
57
|
+
|
|
58
|
+
*******************************************************************************
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class EditProfileTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
context 'Editing a user profile' do
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
@user = Factory(:user, :password => 'password')
|
|
9
|
+
sign_in_as(@user.email, 'password')
|
|
10
|
+
visit edit_user_path(@user)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
should_respond_with :success
|
|
14
|
+
|
|
15
|
+
should "see the form with his info" do
|
|
16
|
+
assert_select "input#user_first_name[value='#{@user.first_name}']"
|
|
17
|
+
assert_select "input#user_last_name[value='#{@user.last_name}']"
|
|
18
|
+
assert_select "input#user_email[value='#{@user.email}']"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should "update valid information and see the SHOW page" do
|
|
22
|
+
fill_in "user_first_name", :with => 'OtherName'
|
|
23
|
+
click_button 'Save'
|
|
24
|
+
assert_contain /othername/i
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
should "update invalid information and see errors" do
|
|
28
|
+
fill_in "user_first_name", :with => ''
|
|
29
|
+
click_button 'Save'
|
|
30
|
+
assert_contain /First name .* blank/i
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class FacebookTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
if Headstart.configuration.use_facebook_connect
|
|
6
|
+
|
|
7
|
+
context 'Signing in with Facebook' do
|
|
8
|
+
|
|
9
|
+
setup do
|
|
10
|
+
cookies[Headstart.configuration.facebook_api_key + "_user"] = "8055"
|
|
11
|
+
cookies[Headstart.configuration.facebook_api_key + "_session_key"] = "123456789"
|
|
12
|
+
FakeWeb.register_uri(:post,
|
|
13
|
+
%r|http://api.facebook.com/restserver.php|,
|
|
14
|
+
:body => '[{"about_me":"","activities":"","affiliations":{},"birthday":"July 18","books":"","current_location":{"city":"Orlando","state":"Florida","country":"United States","zip":""},"education_history":[{"name":"Florida Institute of Technology","year":1995,"concentrations":{},"degree":"","school_type":"Unknown"}],"first_name":"Bob","hometown_location":null,"hs_info":{"hs1_name":"Cheyenne Mountain High School","hs2_name":"","grad_year":1992,"hs1_id":3202,"hs2_id":0},"interests":"","is_app_user":true,"last_name":"Jones","meeting_for":{},"meeting_sex":{},"movies":"","music":"","name":"Bob Jones","notes_count":null,"pic":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-sf2p\/hs272.snc3\/23197_1334019372_5345_s.jpg","pic_big":"http:\/\/profile.ak.fbcdn.net\/v228\/245\/118\/n1334019372_6158.jpg","pic_small":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-sf2p\/hs272.snc3\/23197_1334019372_5345_t.jpg","political":"","profile_update_time":1267034911,"quotes":"","relationship_status":"","religion":"","sex":"male","significant_other_id":null,"status":{"message":"","time":0,"status_id":0},"timezone":-5,"tv":"","uid":8055,"wall_count":34,"work_history":{},"pic_square":"http:\/\/profile.ak.fbcdn.net\/hprofile-ak-sf2p\/hs272.snc3\/23197_1334019372_5345_q.jpg","has_added_app":true,"email_hashes":{},"locale":"en_US","profile_url":"http:\/\/www.facebook.com\/profile.php?id=1334019372","proxied_email":"apps+339309032618.1334019372.a320f4a38471f7b537079f5c13bb33f1@proxymail.facebook.com","pic_big_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=20fef10357c21b2e1acc8dac7d4bed49&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fv228%2F245%2F118%2Fn1334019372_6158.jpg&v=5","pic_small_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=ad4b560e363f5b40ccbe81e1d985c91e&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-sf2p%2Fhs272.snc3%2F23197_1334019372_5345_t.jpg&v=5","pic_square_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=a0118842ed70fce04e7883f5ab52023f&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-sf2p%2Fhs272.snc3%2F23197_1334019372_5345_q.jpg&v=5","pic_with_logo":"http:\/\/external.ak.fbcdn.net\/safe_image.php?logo&d=eb90cc8c5f332436f5d56009aab6b467&url=http%3A%2F%2Fprofile.ak.fbcdn.net%2Fhprofile-ak-sf2p%2Fhs272.snc3%2F23197_1334019372_5345_s.jpg&v=5","birthday_date":"07\/18","email":"bob@example.com","allowed_restrictions":"alcohol"}]'
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
teardown do
|
|
19
|
+
cookies[Headstart.configuration.facebook_api_key + "_user"] = nil
|
|
20
|
+
cookies[Headstart.configuration.facebook_api_key + "_session_key"] = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
should 'find an existing user with the facebook uid' do
|
|
24
|
+
user = Factory( :facebook_user,
|
|
25
|
+
:facebook_uid => 8055,
|
|
26
|
+
:email => 'bob@facebook.com')
|
|
27
|
+
|
|
28
|
+
visit fb_connect_url
|
|
29
|
+
assert controller.signed_in?
|
|
30
|
+
assert_equal controller.current_user, user
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
should 'find an existing user with the facebook email address' do
|
|
34
|
+
user = Factory( :user,
|
|
35
|
+
:facebook_uid => nil,
|
|
36
|
+
:email => 'bob@example.com')
|
|
37
|
+
|
|
38
|
+
visit fb_connect_url
|
|
39
|
+
assert controller.signed_in?
|
|
40
|
+
assert_equal controller.current_user, user
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
should 'create a new user when the facebook uid is not found' do
|
|
44
|
+
assert_nil User.find_by_facebook_uid(8055)
|
|
45
|
+
|
|
46
|
+
visit fb_connect_url
|
|
47
|
+
assert controller.signed_in?
|
|
48
|
+
assert_equal '8055', controller.current_user.facebook_uid
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
should 'copy the facebook user details' do
|
|
52
|
+
visit fb_connect_url
|
|
53
|
+
assert controller.signed_in?
|
|
54
|
+
assert_equal 'bob@example.com', controller.current_user.email
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ImpersonationTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
context 'When impersonating another user' do
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
@bob = Factory(:user, :email => 'bob@bob.bob')
|
|
9
|
+
@admin_user = Factory(:admin_user, :email => 'admin@example.com')
|
|
10
|
+
sign_in_as @admin_user.email, @admin_user.password
|
|
11
|
+
impersonate(@bob)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should 'be signed in' do
|
|
15
|
+
assert controller.signed_in?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
should 'be logged in as bob' do
|
|
19
|
+
assert_equal controller.current_user, @bob
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should 'be able to go back to the original admin user' do
|
|
23
|
+
click_link "Stop impersonating"
|
|
24
|
+
assert controller.signed_in?
|
|
25
|
+
assert_equal controller.current_user, @admin_user
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def impersonate(user)
|
|
35
|
+
visit impersonations_url
|
|
36
|
+
click_link "impersonate_#{user.id}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class PasswordResetTest < ActionController::IntegrationTest
|
|
4
|
+
|
|
5
|
+
context 'When requesting a password reset' do
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
ActionMailer::Base.deliveries.clear
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
teardown do
|
|
12
|
+
ActionMailer::Base.deliveries.clear
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context 'when not signed up' do
|
|
16
|
+
|
|
17
|
+
should 'see "Unknown email"' do
|
|
18
|
+
request_password_reset('unknown@bob.bob')
|
|
19
|
+
assert_match(/Unknown email/, response.body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should 'not send an email' do
|
|
23
|
+
request_password_reset('unknown@bob.bob')
|
|
24
|
+
assert ActionMailer::Base.deliveries.empty?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'when signed up' do
|
|
30
|
+
|
|
31
|
+
setup do
|
|
32
|
+
@user = Factory(:user, :email => 'bob@bob.bob')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should 'see "instructions for changing your password"' do
|
|
36
|
+
request_password_reset(@user.email)
|
|
37
|
+
assert_match(/instructions for changing your password/, response.body)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
should 'send a password reset email to the user' do
|
|
41
|
+
request_password_reset(@user.email)
|
|
42
|
+
@user.reload # catch updated confirmation token
|
|
43
|
+
Delayed::Job.work_off
|
|
44
|
+
assert !@user.password_reset_token.blank?
|
|
45
|
+
assert_sent_email do |email|
|
|
46
|
+
email.recipients =~ /#{Regexp.escape @user.email}/i &&
|
|
47
|
+
email.subject =~ /password/i &&
|
|
48
|
+
email.body[:url] =~ /#{Regexp.escape @user.password_reset_token}/
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context 'After requesting a password reset' do
|
|
57
|
+
|
|
58
|
+
setup do
|
|
59
|
+
ActionMailer::Base.deliveries.clear
|
|
60
|
+
@user = Factory(:user, :email => 'bob@bob.bob')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
teardown do
|
|
64
|
+
ActionMailer::Base.deliveries.clear
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'with failed password confirmation' do
|
|
68
|
+
|
|
69
|
+
should 'see error messages' do
|
|
70
|
+
request_password_reset('bob@bob.bob')
|
|
71
|
+
@user.reload
|
|
72
|
+
change_password(@user, :password => 'goodpassword', :confirm => 'badpassword')
|
|
73
|
+
assert_match(/Password doesn't match confirmation/, response.body)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
should 'not be signed in' do
|
|
77
|
+
request_password_reset('bob@bob.bob')
|
|
78
|
+
@user.reload
|
|
79
|
+
change_password(@user, :password => 'goodpassword', :confirm => 'badpassword')
|
|
80
|
+
assert !controller.signed_in?
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'with valid password and confirmation' do
|
|
86
|
+
|
|
87
|
+
should 'be signed in' do
|
|
88
|
+
request_password_reset('bob@bob.bob')
|
|
89
|
+
@user.reload
|
|
90
|
+
change_password(@user)
|
|
91
|
+
assert controller.signed_in?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
should 'be able to sign in with new password' do
|
|
95
|
+
request_password_reset('bob@bob.bob')
|
|
96
|
+
@user.reload
|
|
97
|
+
change_password(@user)
|
|
98
|
+
sign_out
|
|
99
|
+
sign_in_as('bob@bob.bob', 'goodpassword')
|
|
100
|
+
assert controller.signed_in?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def request_password_reset(email)
|
|
112
|
+
visit new_password_url
|
|
113
|
+
fill_in "Email Address", :with => email
|
|
114
|
+
click_button "reset password"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def change_password(user, options = {})
|
|
118
|
+
options[:password] ||= 'goodpassword'
|
|
119
|
+
options[:confirm] ||= options[:password]
|
|
120
|
+
|
|
121
|
+
visit edit_user_password_path(:user_id => user,
|
|
122
|
+
:token => user.password_reset_token)
|
|
123
|
+
fill_in "Choose password", :with => options[:password]
|
|
124
|
+
fill_in "Confirm password", :with => options[:confirm]
|
|
125
|
+
click_button "save this password"
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|