1
1
require 'test_helper'
2
2
3
3
class Manage ::UsersControllerTest < ActionController ::TestCase
4
+ include ActiveJob ::TestHelper
5
+
4
6
setup do
5
7
@user = create ( :user )
6
8
end
@@ -12,6 +14,16 @@ class Manage::UsersControllerTest < ActionController::TestCase
12
14
assert_redirected_to new_user_session_path
13
15
end
14
16
17
+ should "not allow access to user_datatable" do
18
+ get :user_datatable
19
+ assert_redirected_to new_user_session_path
20
+ end
21
+
22
+ should "not allow access to staff_datatable" do
23
+ get :staff_datatable
24
+ assert_redirected_to new_user_session_path
25
+ end
26
+
15
27
should "not allow access to manage_users user datatables api" do
16
28
post :user_datatable , format : :json , params : { "columns[0][data]" => "" }
17
29
assert_response 401
@@ -59,6 +71,16 @@ class Manage::UsersControllerTest < ActionController::TestCase
59
71
assert_redirected_to root_path
60
72
end
61
73
74
+ should "not allow access to user_datatable" do
75
+ get :user_datatable
76
+ assert_redirected_to root_path
77
+ end
78
+
79
+ should "not allow access to staff_datatable" do
80
+ get :staff_datatable
81
+ assert_redirected_to root_path
82
+ end
83
+
62
84
should "not allow access to manage_users users datatables api" do
63
85
post :user_datatable , format : :json , params : { "columns[0][data]" => "" }
64
86
assert_response :redirect
@@ -108,6 +130,16 @@ class Manage::UsersControllerTest < ActionController::TestCase
108
130
assert_redirected_to manage_checkins_path
109
131
end
110
132
133
+ should "not allow access to user_datatable" do
134
+ get :user_datatable
135
+ assert_redirected_to manage_checkins_path
136
+ end
137
+
138
+ should "not allow access to staff_datatable" do
139
+ get :staff_datatable
140
+ assert_redirected_to manage_checkins_path
141
+ end
142
+
111
143
should "not allow access to manage_users users datatables api" do
112
144
post :user_datatable , format : :json , params : { "columns[0][data]" => "" }
113
145
assert_redirected_to manage_checkins_path
@@ -154,6 +186,16 @@ class Manage::UsersControllerTest < ActionController::TestCase
154
186
assert_redirected_to manage_root_path
155
187
end
156
188
189
+ should "not allow access to user_datatable" do
190
+ get :user_datatable
191
+ assert_redirected_to manage_root_path
192
+ end
193
+
194
+ should "not allow access to staff_datatable" do
195
+ get :staff_datatable
196
+ assert_redirected_to manage_root_path
197
+ end
198
+
157
199
should "not allow access to manage_users users datatables api" do
158
200
post :user_datatable , format : :json , params : { "columns[0][data]" => "" }
159
201
assert_redirected_to manage_root_path
@@ -200,55 +242,51 @@ class Manage::UsersControllerTest < ActionController::TestCase
200
242
assert_response :success
201
243
end
202
244
203
- # TODO: Tests appear to be stalling Travis CI
204
-
205
- # should "create a new admin" do
206
- # post :create, params: { user: { email: "[email protected] ", role: 'admin' } }
207
- # assert_response :redirect
208
- # assert_redirected_to manage_users_path
209
- # assert assigns(:user).admin?, "new user should be an admin"
210
- # end
211
-
212
- # should "create a new limited access admin" do
213
- # post :create, params: { user: { email: "[email protected] ", role: 'admin_limited_access' } }
214
- # assert_response :redirect
215
- # assert_redirected_to manage_users_path
216
- # assert !assigns(:user).admin?, "new user should not be an admin"
217
- # assert assigns(:user).admin_limited_access?, "new user should be a limited access admin"
218
- # end
219
-
220
- # should "not create an admin with duplicate emails" do
221
- # create(:user, email: "[email protected] ")
222
- # assert_difference('User.count', 0) do
223
- # post :create, params: { user: { email: "[email protected] ", role: 'admin' } }
224
- # end
225
- # end
226
-
227
- # should "allow access to manage_admins#new" do
228
- # get :new, params: { id: @user }
229
- # assert_response :success
230
- # end
231
-
232
- # should "allow access to manage_admins#show" do
233
- # get :show, params: { id: @user }
234
- # assert_response :success
235
- # end
236
-
237
- # should "allow access to manage_admins#edit" do
238
- # get :edit, params: { id: @user }
239
- # assert_response :success
240
- # end
241
-
242
- # should "update user" do
243
- # patch :update, params: { id: @user, user: { email: "[email protected] " } }
244
- # assert_redirected_to manage_users_path
245
- # end
246
-
247
- # should "destroy user" do
248
- # assert_difference('User.count', -1) do
249
- # patch :destroy, params: { id: @user }
250
- # end
251
- # assert_redirected_to manage_users_path
252
- # end
245
+ should "allow access to user_datatable" do
246
+ get :user_datatable
247
+ assert_response :success
248
+ end
249
+
250
+ should "allow access to staff_datatable" do
251
+ get :staff_datatable
252
+ assert_response :success
253
+ end
254
+
255
+ should "be able to reset a user's password" do
256
+ assert_difference "enqueued_jobs.size" , 1 do
257
+ patch :reset_password , params : { id : @user }
258
+ end
259
+ assert_redirected_to manage_users_path
260
+ end
261
+
262
+ should "allow access to manage_users#show" do
263
+ get :show , params : { id : @user }
264
+ assert_response :success
265
+ end
266
+
267
+ should "allow access to manage_users#edit" do
268
+ get :edit , params : { id : @user }
269
+ assert_response :success
270
+ end
271
+
272
+ should "update user" do
273
+ patch :update , params :
{ id :
@user , user :
{ email :
"[email protected] " } }
274
+ assert_redirected_to manage_users_path
275
+ end
276
+
277
+ should "destroy user" do
278
+ assert_difference ( 'User.count' , -1 ) do
279
+ patch :destroy , params : { id : @user }
280
+ end
281
+ assert_redirected_to manage_users_path
282
+ end
283
+
284
+ should "destroy user and user's questionnaire" do
285
+ @questionnaire = create ( :questionnaire , user_id : @user . id )
286
+ assert_difference ( 'Questionnaire.count' , -1 ) do
287
+ patch :destroy , params : { id : @user }
288
+ end
289
+ assert_redirected_to manage_users_path
290
+ end
253
291
end
254
292
end
0 commit comments