devise_token_auth 0.1.42 → 0.1.43.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise_token_auth might be problematic. Click here for more details.

Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -38
  3. data/app/controllers/devise_token_auth/application_controller.rb +15 -0
  4. data/app/controllers/devise_token_auth/concerns/resource_finder.rb +38 -0
  5. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +21 -19
  6. data/app/controllers/devise_token_auth/confirmations_controller.rb +12 -7
  7. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +3 -7
  8. data/app/controllers/devise_token_auth/passwords_controller.rb +16 -26
  9. data/app/controllers/devise_token_auth/registrations_controller.rb +6 -2
  10. data/app/controllers/devise_token_auth/sessions_controller.rb +3 -14
  11. data/app/controllers/devise_token_auth/unlocks_controller.rb +105 -0
  12. data/app/models/devise_token_auth/concerns/user.rb +29 -12
  13. data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +5 -8
  14. data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
  15. data/app/views/devise_token_auth/omniauth_external_window.html.erb +1 -1
  16. data/config/initializers/devise.rb +1 -1
  17. data/config/locales/da-DK.yml +50 -0
  18. data/config/locales/en.yml +4 -0
  19. data/lib/devise_token_auth/controllers/helpers.rb +30 -20
  20. data/lib/devise_token_auth/rails/routes.rb +1 -1
  21. data/lib/devise_token_auth/url.rb +1 -1
  22. data/lib/devise_token_auth/version.rb +1 -1
  23. data/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +2 -1
  24. data/lib/generators/devise_token_auth/templates/user.rb +1 -1
  25. data/test/controllers/custom/custom_confirmations_controller_test.rb +5 -10
  26. data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +15 -16
  27. data/test/controllers/custom/custom_passwords_controller_test.rb +28 -34
  28. data/test/controllers/custom/custom_registrations_controller_test.rb +23 -21
  29. data/test/controllers/custom/custom_sessions_controller_test.rb +16 -18
  30. data/test/controllers/custom/custom_token_validations_controller_test.rb +13 -11
  31. data/test/controllers/demo_group_controller_test.rb +19 -5
  32. data/test/controllers/demo_mang_controller_test.rb +37 -16
  33. data/test/controllers/demo_user_controller_test.rb +70 -38
  34. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +40 -22
  35. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +108 -82
  36. data/test/controllers/devise_token_auth/passwords_controller_test.rb +127 -145
  37. data/test/controllers/devise_token_auth/registrations_controller_test.rb +258 -274
  38. data/test/controllers/devise_token_auth/sessions_controller_test.rb +112 -117
  39. data/test/controllers/devise_token_auth/token_validations_controller_test.rb +14 -15
  40. data/test/controllers/devise_token_auth/unlocks_controller_test.rb +194 -0
  41. data/test/controllers/overrides/confirmations_controller_test.rb +8 -9
  42. data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +16 -12
  43. data/test/controllers/overrides/passwords_controller_test.rb +19 -15
  44. data/test/controllers/overrides/registrations_controller_test.rb +7 -7
  45. data/test/controllers/overrides/sessions_controller_test.rb +6 -6
  46. data/test/controllers/overrides/token_validations_controller_test.rb +7 -4
  47. data/test/dummy/app/controllers/auth_origin_controller.rb +2 -2
  48. data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +0 -2
  49. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +11 -7
  50. data/test/dummy/app/controllers/overrides/passwords_controller.rb +10 -8
  51. data/test/dummy/app/controllers/overrides/sessions_controller.rb +1 -1
  52. data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +2 -2
  53. data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +2 -2
  54. data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +1 -1
  55. data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +1 -1
  56. data/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +2 -1
  57. data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +1 -1
  58. data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +2 -1
  59. data/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb +2 -1
  60. data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +2 -1
  61. data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +2 -1
  62. data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +2 -1
  63. data/test/dummy/db/schema.rb +157 -162
  64. data/test/dummy/tmp/generators/app/models/user.rb +1 -1
  65. data/test/dummy/tmp/generators/db/migrate/{20170517171822_devise_token_auth_create_users.rb → 20171014052631_devise_token_auth_create_users.rb} +2 -1
  66. data/test/lib/generators/devise_token_auth/install_generator_test.rb +5 -1
  67. data/test/models/user_test.rb +35 -1
  68. data/test/test_helper.rb +17 -11
  69. metadata +85 -80
@@ -6,13 +6,12 @@ require 'test_helper'
6
6
  # was the correct object stored in the response?
7
7
  # was the appropriate message delivered in the json payload?
8
8
 
9
-
10
9
  class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::IntegrationTest
11
10
  describe DeviseTokenAuth::RegistrationsController do
12
11
  describe 'Validate non-empty body' do
13
12
  before do
14
13
  # need to post empty data
15
- post '/auth', {}
14
+ post '/auth', params: {}
16
15
 
17
16
  @resource = assigns(:resource)
18
17
  @data = JSON.parse(response.body)
@@ -35,48 +34,49 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
35
34
  end
36
35
  end
37
36
 
38
- describe "Successful registration" do
37
+ describe 'Successful registration' do
39
38
  before do
40
39
  @mails_sent = ActionMailer::Base.deliveries.count
41
40
 
42
- post '/auth', {
43
- email: Faker::Internet.email,
44
- password: "secret123",
45
- password_confirmation: "secret123",
46
- confirm_success_url: Faker::Internet.url,
47
- unpermitted_param: '(x_x)'
48
- }
41
+ post '/auth',
42
+ params: {
43
+ email: Faker::Internet.email,
44
+ password: 'secret123',
45
+ password_confirmation: 'secret123',
46
+ confirm_success_url: Faker::Internet.url,
47
+ unpermitted_param: '(x_x)'
48
+ }
49
49
 
50
50
  @resource = assigns(:resource)
51
51
  @data = JSON.parse(response.body)
52
52
  @mail = ActionMailer::Base.deliveries.last
53
53
  end
54
54
 
55
- test "request should be successful" do
55
+ test 'request should be successful' do
56
56
  assert_equal 200, response.status
57
57
  end
58
58
 
59
- test "user should have been created" do
59
+ test 'user should have been created' do
60
60
  assert @resource.id
61
61
  end
62
62
 
63
- test "user should not be confirmed" do
63
+ test 'user should not be confirmed' do
64
64
  assert_nil @resource.confirmed_at
65
65
  end
66
66
 
67
- test "new user data should be returned as json" do
67
+ test 'new user data should be returned as json' do
68
68
  assert @data['data']['email']
69
69
  end
70
70
 
71
- test "new user should receive confirmation email" do
71
+ test 'new user should receive confirmation email' do
72
72
  assert_equal @resource.email, @mail['to'].to_s
73
73
  end
74
74
 
75
- test "new user password should not be returned" do
75
+ test 'new user password should not be returned' do
76
76
  assert_nil @data['data']['password']
77
77
  end
78
78
 
79
- test "only one email was sent" do
79
+ test 'only one email was sent' do
80
80
  assert_equal @mails_sent + 1, ActionMailer::Base.deliveries.count
81
81
  end
82
82
  end
@@ -85,12 +85,11 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
85
85
  test 'can use + sign in email addresses' do
86
86
  @plus_email = 'ak+testing@gmail.com'
87
87
 
88
- post '/auth', {
89
- email: @plus_email,
90
- password: "secret123",
91
- password_confirmation: "secret123",
92
- confirm_success_url: Faker::Internet.url
93
- }
88
+ post '/auth',
89
+ params: { email: @plus_email,
90
+ password: 'secret123',
91
+ password_confirmation: 'secret123',
92
+ confirm_success_url: Faker::Internet.url }
94
93
 
95
94
  @resource = assigns(:resource)
96
95
 
@@ -109,58 +108,55 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
109
108
  DeviseTokenAuth.redirect_whitelist = nil
110
109
  end
111
110
 
112
- test "request to whitelisted redirect should be successful" do
113
- post '/auth', {
114
- email: Faker::Internet.email,
115
- password: "secret123",
116
- password_confirmation: "secret123",
117
- confirm_success_url: @good_redirect_url,
118
- unpermitted_param: '(x_x)'
119
- }
111
+ test 'request to whitelisted redirect should be successful' do
112
+ post '/auth',
113
+ params: { email: Faker::Internet.email,
114
+ password: 'secret123',
115
+ password_confirmation: 'secret123',
116
+ confirm_success_url: @good_redirect_url,
117
+ unpermitted_param: '(x_x)' }
120
118
 
121
119
  assert_equal 200, response.status
122
120
  end
123
121
 
124
- test "request to non-whitelisted redirect should fail" do
125
- post '/auth', {
126
- email: Faker::Internet.email,
127
- password: "secret123",
128
- password_confirmation: "secret123",
129
- confirm_success_url: @bad_redirect_url,
130
- unpermitted_param: '(x_x)'
131
- }
122
+ test 'request to non-whitelisted redirect should fail' do
123
+ post '/auth',
124
+ params: { email: Faker::Internet.email,
125
+ password: 'secret123',
126
+ password_confirmation: 'secret123',
127
+ confirm_success_url: @bad_redirect_url,
128
+ unpermitted_param: '(x_x)' }
132
129
  @data = JSON.parse(response.body)
133
130
 
134
131
  assert_equal 422, response.status
135
- assert @data["errors"]
136
- assert_equal @data["errors"], [I18n.t("devise_token_auth.registrations.redirect_url_not_allowed", redirect_url: @bad_redirect_url)]
132
+ assert @data['errors']
133
+ assert_equal @data['errors'],
134
+ [I18n.t('devise_token_auth.registrations.redirect_url_not_allowed',
135
+ redirect_url: @bad_redirect_url)]
137
136
  end
138
137
  end
139
138
 
140
139
  describe 'failure if not redirecturl' do
141
-
142
- test "request should fail if not redirect_url" do
143
- post '/auth', {
144
- email: Faker::Internet.email,
145
- password: "secret123",
146
- password_confirmation: "secret123",
147
- unpermitted_param: '(x_x)'
148
- }
140
+ test 'request should fail if not redirect_url' do
141
+ post '/auth',
142
+ params: { email: Faker::Internet.email,
143
+ password: 'secret123',
144
+ password_confirmation: 'secret123',
145
+ unpermitted_param: '(x_x)' }
149
146
 
150
147
  assert_equal 422, response.status
151
148
  end
152
149
 
153
- test "request to non-whitelisted redirect should fail" do
154
- post '/auth', {
155
- email: Faker::Internet.email,
156
- password: "secret123",
157
- password_confirmation: "secret123",
158
- unpermitted_param: '(x_x)'
159
- }
150
+ test 'request to non-whitelisted redirect should fail' do
151
+ post '/auth',
152
+ params: { email: Faker::Internet.email,
153
+ password: 'secret123',
154
+ password_confirmation: 'secret123',
155
+ unpermitted_param: '(x_x)' }
160
156
  @data = JSON.parse(response.body)
161
157
 
162
- assert @data["errors"]
163
- assert_equal @data["errors"], [I18n.t("devise_token_auth.registrations.missing_confirm_success_url")]
158
+ assert @data['errors']
159
+ assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.missing_confirm_success_url')]
164
160
  end
165
161
  end
166
162
 
@@ -171,12 +167,12 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
171
167
 
172
168
  DeviseTokenAuth.default_confirm_success_url = @redirect_url
173
169
 
174
- post '/auth', {
175
- email: Faker::Internet.email,
176
- password: "secret123",
177
- password_confirmation: "secret123",
178
- unpermitted_param: '(x_x)'
179
- }
170
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
171
+ post '/auth', params: { email: Faker::Internet.email,
172
+ password: 'secret123',
173
+ password_confirmation: 'secret123',
174
+ unpermitted_param: '(x_x)' }
175
+ end
180
176
 
181
177
  @resource = assigns(:resource)
182
178
  @data = JSON.parse(response.body)
@@ -188,14 +184,10 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
188
184
  DeviseTokenAuth.default_confirm_success_url = nil
189
185
  end
190
186
 
191
- test "request should be successful" do
187
+ test 'request should be successful' do
192
188
  assert_equal 200, response.status
193
189
  end
194
190
 
195
- test "the email was sent" do
196
- assert_equal @mails_sent + 1, ActionMailer::Base.deliveries.count
197
- end
198
-
199
191
  test 'email contains the default redirect url' do
200
192
  assert_equal @redirect_url, @sent_redirect_url
201
193
  end
@@ -205,10 +197,10 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
205
197
  before do
206
198
  @mails_sent = ActionMailer::Base.deliveries.count
207
199
 
208
- post '/api/v1/auth', {
200
+ post '/api/v1/auth', params: {
209
201
  email: Faker::Internet.email,
210
- password: "secret123",
211
- password_confirmation: "secret123",
202
+ password: 'secret123',
203
+ password_confirmation: 'secret123',
212
204
  confirm_success_url: Faker::Internet.url,
213
205
  unpermitted_param: '(x_x)'
214
206
  }
@@ -218,58 +210,55 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
218
210
  @mail = ActionMailer::Base.deliveries.last
219
211
  end
220
212
 
221
- test "request should be successful" do
213
+ test 'request should be successful' do
222
214
  assert_equal 200, response.status
223
215
  end
224
216
 
225
- test "user should have been created" do
217
+ test 'user should have been created' do
226
218
  assert @resource.id
227
219
  end
228
220
  end
229
221
 
230
- describe "case-insensitive email" do
231
-
222
+ describe 'case-insensitive email' do
232
223
  before do
233
224
  @resource_class = User
234
225
  @request_params = {
235
- email: "AlternatingCase@example.com",
236
- password: "secret123",
237
- password_confirmation: "secret123",
226
+ email: 'AlternatingCase@example.com',
227
+ password: 'secret123',
228
+ password_confirmation: 'secret123',
238
229
  confirm_success_url: Faker::Internet.url
239
230
  }
240
231
  end
241
232
 
242
- test "success should downcase uid if configured" do
233
+ test 'success should downcase uid if configured' do
243
234
  @resource_class.case_insensitive_keys = [:email]
244
- post '/auth', @request_params
235
+ post '/auth', params: @request_params
245
236
  assert_equal 200, response.status
246
237
  @data = JSON.parse(response.body)
247
- assert_equal "alternatingcase@example.com", @data['data']['uid']
238
+ assert_equal 'alternatingcase@example.com', @data['data']['uid']
248
239
  end
249
240
 
250
- test "request should not downcase uid if not configured" do
241
+ test 'request should not downcase uid if not configured' do
251
242
  @resource_class.case_insensitive_keys = []
252
- post '/auth', @request_params
243
+ post '/auth', params: @request_params
253
244
  assert_equal 200, response.status
254
245
  @data = JSON.parse(response.body)
255
- assert_equal "AlternatingCase@example.com", @data['data']['uid']
246
+ assert_equal 'AlternatingCase@example.com', @data['data']['uid']
256
247
  end
257
-
258
248
  end
259
249
 
260
- describe "Adding extra params" do
250
+ describe 'Adding extra params' do
261
251
  before do
262
252
  @redirect_url = Faker::Internet.url
263
253
  @operating_thetan = 2
264
254
 
265
- post '/auth', {
266
- email: Faker::Internet.email,
267
- password: "secret123",
268
- password_confirmation: "secret123",
269
- confirm_success_url: @redirect_url,
270
- favorite_color: @fav_color,
271
- operating_thetan: @operating_thetan
272
- }
255
+ post '/auth',
256
+ params: { email: Faker::Internet.email,
257
+ password: 'secret123',
258
+ password_confirmation: 'secret123',
259
+ confirm_success_url: @redirect_url,
260
+ favorite_color: @fav_color,
261
+ operating_thetan: @operating_thetan }
273
262
 
274
263
  @resource = assigns(:resource)
275
264
  @data = JSON.parse(response.body)
@@ -284,7 +273,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
284
273
  assert_equal @redirect_url, @mail_redirect_url
285
274
  end
286
275
 
287
- test "additional sign_up params should be considered" do
276
+ test 'additional sign_up params should be considered' do
288
277
  assert_equal @operating_thetan, @resource.operating_thetan
289
278
  end
290
279
 
@@ -293,130 +282,125 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
293
282
  end
294
283
 
295
284
  test "client config name falls back to 'default'" do
296
- assert_equal "default", @mail_config_name
285
+ assert_equal 'default', @mail_config_name
297
286
  end
298
287
  end
299
288
 
300
289
  describe 'bad email' do
301
290
  before do
302
- post '/auth', {
303
- email: "false_email@",
304
- password: "secret123",
305
- password_confirmation: "secret123",
306
- confirm_success_url: Faker::Internet.url
307
- }
291
+ post '/auth',
292
+ params: { email: 'false_email@',
293
+ password: 'secret123',
294
+ password_confirmation: 'secret123',
295
+ confirm_success_url: Faker::Internet.url }
308
296
 
309
297
  @resource = assigns(:resource)
310
298
  @data = JSON.parse(response.body)
311
299
  end
312
300
 
313
- test "request should not be successful" do
301
+ test 'request should not be successful' do
314
302
  assert_equal 422, response.status
315
303
  end
316
304
 
317
- test "user should not have been created" do
305
+ test 'user should not have been created' do
318
306
  assert_nil @resource.id
319
307
  end
320
308
 
321
- test "error should be returned in the response" do
309
+ test 'error should be returned in the response' do
322
310
  assert @data['errors'].length
323
311
  end
324
312
 
325
- test "full_messages should be included in error hash" do
313
+ test 'full_messages should be included in error hash' do
326
314
  assert @data['errors']['full_messages'].length
327
315
  end
328
316
  end
329
317
 
330
318
  describe 'missing email' do
331
319
  before do
332
- post '/auth', {
333
- password: "secret123",
334
- password_confirmation: "secret123",
335
- confirm_success_url: Faker::Internet.url
336
- }
320
+ post '/auth',
321
+ params: { password: 'secret123',
322
+ password_confirmation: 'secret123',
323
+ confirm_success_url: Faker::Internet.url }
337
324
 
338
325
  @resource = assigns(:resource)
339
326
  @data = JSON.parse(response.body)
340
327
  end
341
328
 
342
- test "request should not be successful" do
329
+ test 'request should not be successful' do
343
330
  assert_equal 422, response.status
344
331
  end
345
332
 
346
- test "user should not have been created" do
333
+ test 'user should not have been created' do
347
334
  assert_nil @resource.id
348
335
  end
349
336
 
350
- test "error should be returned in the response" do
337
+ test 'error should be returned in the response' do
351
338
  assert @data['errors'].length
352
339
  end
353
340
 
354
- test "full_messages should be included in error hash" do
341
+ test 'full_messages should be included in error hash' do
355
342
  assert @data['errors']['full_messages'].length
356
343
  end
357
344
  end
358
345
 
359
- describe "Mismatched passwords" do
346
+ describe 'Mismatched passwords' do
360
347
  before do
361
- post '/auth', {
362
- email: Faker::Internet.email,
363
- password: "secret123",
364
- password_confirmation: "bogus",
365
- confirm_success_url: Faker::Internet.url
366
- }
348
+ post '/auth',
349
+ params: { email: Faker::Internet.email,
350
+ password: 'secret123',
351
+ password_confirmation: 'bogus',
352
+ confirm_success_url: Faker::Internet.url }
367
353
 
368
354
  @resource = assigns(:resource)
369
355
  @data = JSON.parse(response.body)
370
356
  end
371
357
 
372
- test "request should not be successful" do
358
+ test 'request should not be successful' do
373
359
  assert_equal 422, response.status
374
360
  end
375
361
 
376
- test "user should have been created" do
362
+ test 'user should have been created' do
377
363
  assert_nil @resource.id
378
364
  end
379
365
 
380
- test "error should be returned in the response" do
366
+ test 'error should be returned in the response' do
381
367
  assert @data['errors'].length
382
368
  end
383
369
 
384
- test "full_messages should be included in error hash" do
370
+ test 'full_messages should be included in error hash' do
385
371
  assert @data['errors']['full_messages'].length
386
372
  end
387
373
  end
388
374
 
389
- describe "Existing users" do
375
+ describe 'Existing users' do
390
376
  before do
391
377
  @existing_user = users(:confirmed_email_user)
392
378
 
393
- post "/auth", {
394
- email: @existing_user.email,
395
- password: "secret123",
396
- password_confirmation: "secret123",
397
- confirm_success_url: Faker::Internet.url
398
- }
379
+ post '/auth',
380
+ params: { email: @existing_user.email,
381
+ password: 'secret123',
382
+ password_confirmation: 'secret123',
383
+ confirm_success_url: Faker::Internet.url }
399
384
 
400
385
  @resource = assigns(:resource)
401
386
  @data = JSON.parse(response.body)
402
387
  end
403
388
 
404
- test "request should not be successful" do
389
+ test 'request should not be successful' do
405
390
  assert_equal 422, response.status
406
391
  end
407
392
 
408
- test "user should have been created" do
393
+ test 'user should have been created' do
409
394
  assert_nil @resource.id
410
395
  end
411
396
 
412
- test "error should be returned in the response" do
397
+ test 'error should be returned in the response' do
413
398
  assert @data['errors'].length
414
399
  end
415
400
  end
416
401
 
417
-
418
- describe "Destroy user account" do
419
- describe "success" do
402
+ describe 'Destroy user account' do
403
+ describe 'success' do
420
404
  before do
421
405
  @existing_user = users(:confirmed_email_user)
422
406
  @auth_headers = @existing_user.create_new_auth_token
@@ -425,7 +409,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
425
409
  # ensure request is not treated as batch request
426
410
  age_token(@existing_user, @client_id)
427
411
 
428
- delete "/auth", {}, @auth_headers
412
+ delete '/auth', params: {}, headers: @auth_headers
429
413
 
430
414
  @data = JSON.parse(response.body)
431
415
  end
@@ -434,18 +418,20 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
434
418
  assert_equal 200, response.status
435
419
  end
436
420
 
437
- test "message should be returned" do
438
- assert @data["message"]
439
- assert_equal @data["message"], I18n.t("devise_token_auth.registrations.account_with_uid_destroyed", uid: @existing_user.uid)
421
+ test 'message should be returned' do
422
+ assert @data['message']
423
+ assert_equal @data['message'],
424
+ I18n.t('devise_token_auth.registrations.account_with_uid_destroyed',
425
+ uid: @existing_user.uid)
440
426
  end
441
- test "existing user should be deleted" do
427
+ test 'existing user should be deleted' do
442
428
  refute User.where(id: @existing_user.id).first
443
429
  end
444
430
  end
445
431
 
446
432
  describe 'failure: no auth headers' do
447
433
  before do
448
- delete "/auth"
434
+ delete '/auth'
449
435
  @data = JSON.parse(response.body)
450
436
  end
451
437
 
@@ -455,14 +441,13 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
455
441
 
456
442
  test 'error should be returned' do
457
443
  assert @data['errors'].length
458
- assert_equal @data['errors'], [I18n.t("devise_token_auth.registrations.account_to_destroy_not_found")]
444
+ assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.account_to_destroy_not_found')]
459
445
  end
460
446
  end
461
447
  end
462
448
 
463
-
464
- describe "Update user account" do
465
- describe "existing user" do
449
+ describe 'Update user account' do
450
+ describe 'existing user' do
466
451
  before do
467
452
  @existing_user = users(:confirmed_email_user)
468
453
  @auth_headers = @existing_user.create_new_auth_token
@@ -472,37 +457,38 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
472
457
  age_token(@existing_user, @client_id)
473
458
  end
474
459
 
475
- describe "without password check" do
476
- describe "success" do
460
+ describe 'without password check' do
461
+ describe 'success' do
477
462
  before do
478
463
  # test valid update param
479
464
  @resource_class = User
480
- @new_operating_thetan = 1000000
481
- @email = "AlternatingCase2@example.com"
465
+ @new_operating_thetan = 1_000_000
466
+ @email = 'AlternatingCase2@example.com'
482
467
  @request_params = {
483
468
  operating_thetan: @new_operating_thetan,
484
469
  email: @email
485
470
  }
486
471
  end
487
472
 
488
- test "Request was successful" do
489
- put "/auth", @request_params, @auth_headers
473
+ test 'Request was successful' do
474
+ put '/auth', params: @request_params, headers: @auth_headers
490
475
  assert_equal 200, response.status
491
476
  end
492
477
 
493
- test "Case sensitive attributes update" do
478
+ test 'Case sensitive attributes update' do
494
479
  @resource_class.case_insensitive_keys = []
495
- put "/auth", @request_params, @auth_headers
480
+ put '/auth', params: @request_params, headers: @auth_headers
496
481
  @data = JSON.parse(response.body)
497
482
  @existing_user.reload
498
- assert_equal @new_operating_thetan, @existing_user.operating_thetan
483
+ assert_equal @new_operating_thetan,
484
+ @existing_user.operating_thetan
499
485
  assert_equal @email, @existing_user.email
500
486
  assert_equal @email, @existing_user.uid
501
487
  end
502
488
 
503
- test "Case insensitive attributes update" do
489
+ test 'Case insensitive attributes update' do
504
490
  @resource_class.case_insensitive_keys = [:email]
505
- put "/auth", @request_params, @auth_headers
491
+ put '/auth', params: @request_params, headers: @auth_headers
506
492
  @data = JSON.parse(response.body)
507
493
  @existing_user.reload
508
494
  assert_equal @new_operating_thetan, @existing_user.operating_thetan
@@ -510,16 +496,14 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
510
496
  assert_equal @email.downcase, @existing_user.uid
511
497
  end
512
498
 
513
- test "Supply current password" do
514
- @request_params.merge!(
515
- current_password: "secret123",
516
- email: "new.email@example.com",
517
- )
499
+ test 'Supply current password' do
500
+ @request_params[:current_password] = 'secret123'
501
+ @request_params[:email] = 'new.email@example.com'
518
502
 
519
- put "/auth", @request_params, @auth_headers
503
+ put '/auth', params: @request_params, headers: @auth_headers
520
504
  @data = JSON.parse(response.body)
521
505
  @existing_user.reload
522
- assert_equal @existing_user.email, "new.email@example.com"
506
+ assert_equal @existing_user.email, 'new.email@example.com'
523
507
  end
524
508
  end
525
509
 
@@ -527,7 +511,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
527
511
  before do
528
512
  # get the email so we can check it wasn't updated
529
513
  @email = @existing_user.email
530
- put '/auth', {}, @auth_headers
514
+ put '/auth', params: {}, headers: @auth_headers
531
515
 
532
516
  @data = JSON.parse(response.body)
533
517
  @existing_user.reload
@@ -550,29 +534,29 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
550
534
  end
551
535
  end
552
536
 
553
- describe "error" do
537
+ describe 'error' do
554
538
  before do
555
539
  # test invalid update param
556
- @new_operating_thetan = "blegh"
557
- put "/auth", {
558
- operating_thetan: @new_operating_thetan
559
- }, @auth_headers
540
+ @new_operating_thetan = 'blegh'
541
+ put '/auth',
542
+ params: { operating_thetan: @new_operating_thetan },
543
+ headers: @auth_headers
560
544
 
561
545
  @data = JSON.parse(response.body)
562
546
  @existing_user.reload
563
547
  end
564
548
 
565
- test "Request was NOT successful" do
549
+ test 'Request was NOT successful' do
566
550
  assert_equal 422, response.status
567
551
  end
568
552
 
569
- test "Errors were provided with response" do
570
- assert @data["errors"].length
553
+ test 'Errors were provided with response' do
554
+ assert @data['errors'].length
571
555
  end
572
556
  end
573
557
  end
574
558
 
575
- describe "with password check for password update only" do
559
+ describe 'with password check for password update only' do
576
560
  before do
577
561
  DeviseTokenAuth.check_current_password_before_update = :password
578
562
  end
@@ -581,25 +565,25 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
581
565
  DeviseTokenAuth.check_current_password_before_update = false
582
566
  end
583
567
 
584
- describe "success without password update" do
568
+ describe 'success without password update' do
585
569
  before do
586
570
  # test valid update param
587
571
  @resource_class = User
588
- @new_operating_thetan = 1000000
589
- @email = "AlternatingCase2@example.com"
572
+ @new_operating_thetan = 1_000_000
573
+ @email = 'AlternatingCase2@example.com'
590
574
  @request_params = {
591
575
  operating_thetan: @new_operating_thetan,
592
576
  email: @email
593
577
  }
594
578
  end
595
579
 
596
- test "Request was successful" do
597
- put "/auth", @request_params, @auth_headers
580
+ test 'Request was successful' do
581
+ put '/auth', params: @request_params, headers: @auth_headers
598
582
  assert_equal 200, response.status
599
583
  end
600
584
  end
601
585
 
602
- describe "success with password update" do
586
+ describe 'success with password update' do
603
587
  before do
604
588
  @existing_user.update password: 'secret123', password_confirmation: 'secret123'
605
589
  @request_params = {
@@ -609,15 +593,16 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
609
593
  }
610
594
  end
611
595
 
612
- test "Request was successful" do
613
- put "/auth", @request_params, @auth_headers
596
+ test 'Request was successful' do
597
+ put '/auth', params: @request_params, headers: @auth_headers
614
598
  assert_equal 200, response.status
615
599
  end
616
600
  end
617
601
 
618
- describe "error with password mismatch" do
602
+ describe 'error with password mismatch' do
619
603
  before do
620
- @existing_user.update password: 'secret123', password_confirmation: 'secret123'
604
+ @existing_user.update password: 'secret123',
605
+ password_confirmation: 'secret123'
621
606
  @request_params = {
622
607
  password: 'the_new_secret456',
623
608
  password_confirmation: 'the_new_secret456',
@@ -625,27 +610,28 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
625
610
  }
626
611
  end
627
612
 
628
- test "Request was NOT successful" do
629
- put "/auth", @request_params, @auth_headers
613
+ test 'Request was NOT successful' do
614
+ put '/auth', params: @request_params, headers: @auth_headers
630
615
  assert_equal 422, response.status
631
616
  end
632
617
  end
633
618
  end
634
619
 
635
- describe "with password check for all attributes" do
620
+ describe 'with password check for all attributes' do
636
621
  before do
637
622
  DeviseTokenAuth.check_current_password_before_update = :password
638
- @new_operating_thetan = 1000000
639
- @email = "AlternatingCase2@example.com"
623
+ @new_operating_thetan = 1_000_000
624
+ @email = 'AlternatingCase2@example.com'
640
625
  end
641
626
 
642
627
  after do
643
628
  DeviseTokenAuth.check_current_password_before_update = false
644
629
  end
645
630
 
646
- describe "success with password update" do
631
+ describe 'success with password update' do
647
632
  before do
648
- @existing_user.update password: 'secret123', password_confirmation: 'secret123'
633
+ @existing_user.update password: 'secret123',
634
+ password_confirmation: 'secret123'
649
635
  @request_params = {
650
636
  operating_thetan: @new_operating_thetan,
651
637
  email: @email,
@@ -653,15 +639,16 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
653
639
  }
654
640
  end
655
641
 
656
- test "Request was successful" do
657
- put "/auth", @request_params, @auth_headers
642
+ test 'Request was successful' do
643
+ put '/auth', params: @request_params, headers: @auth_headers
658
644
  assert_equal 200, response.status
659
645
  end
660
646
  end
661
647
 
662
- describe "error with password mismatch" do
648
+ describe 'error with password mismatch' do
663
649
  before do
664
- @existing_user.update password: 'secret123', password_confirmation: 'secret123'
650
+ @existing_user.update password: 'secret123',
651
+ password_confirmation: 'secret123'
665
652
  @request_params = {
666
653
  operating_thetan: @new_operating_thetan,
667
654
  email: @email,
@@ -669,15 +656,15 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
669
656
  }
670
657
  end
671
658
 
672
- test "Request was NOT successful" do
673
- put "/auth", @request_params, @auth_headers
659
+ test 'Request was NOT successful' do
660
+ put '/auth', params: @request_params, headers: @auth_headers
674
661
  assert_equal 422, response.status
675
662
  end
676
663
  end
677
664
  end
678
665
  end
679
666
 
680
- describe "invalid user" do
667
+ describe 'invalid user' do
681
668
  before do
682
669
  @existing_user = users(:confirmed_email_user)
683
670
  @auth_headers = @existing_user.create_new_auth_token
@@ -689,80 +676,80 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
689
676
  # test valid update param
690
677
  @new_operating_thetan = 3
691
678
 
692
- put "/auth", {
693
- operating_thetan: @new_operating_thetan
694
- }, @auth_headers
679
+ put '/auth',
680
+ params: {
681
+ operating_thetan: @new_operating_thetan
682
+ },
683
+ headers: @auth_headers
695
684
 
696
685
  @data = JSON.parse(response.body)
697
686
  @existing_user.reload
698
687
  end
699
688
 
700
- test "Response should return 404 status" do
689
+ test 'Response should return 404 status' do
701
690
  assert_equal 404, response.status
702
691
  end
703
692
 
704
- test "error should be returned" do
705
- assert @data["errors"].length
706
- assert_equal @data["errors"], [I18n.t("devise_token_auth.registrations.user_not_found")]
693
+ test 'error should be returned' do
694
+ assert @data['errors'].length
695
+ assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.user_not_found')]
707
696
  end
708
697
 
709
- test "User should not be updated" do
698
+ test 'User should not be updated' do
710
699
  refute_equal @new_operating_thetan, @existing_user.operating_thetan
711
700
  end
712
701
  end
713
702
  end
714
703
 
715
- describe "Ouath user has existing email" do
704
+ describe 'Ouath user has existing email' do
716
705
  before do
717
706
  @existing_user = users(:duplicate_email_facebook_user)
718
707
 
719
- post "/auth", {
720
- email: @existing_user.email,
721
- password: "secret123",
722
- password_confirmation: "secret123",
723
- confirm_success_url: Faker::Internet.url
724
- }
708
+ post '/auth',
709
+ params: { email: @existing_user.email,
710
+ password: 'secret123',
711
+ password_confirmation: 'secret123',
712
+ confirm_success_url: Faker::Internet.url }
725
713
 
726
714
  @resource = assigns(:resource)
727
715
  @data = JSON.parse(response.body)
728
716
  end
729
717
 
730
- test "request should be successful" do
718
+ test 'request should be successful' do
731
719
  assert_equal 200, response.status
732
720
  end
733
721
 
734
- test "user should have been created" do
722
+ test 'user should have been created' do
735
723
  assert @resource.id
736
724
  end
737
725
 
738
- test "new user data should be returned as json" do
726
+ test 'new user data should be returned as json' do
739
727
  assert @data['data']['email']
740
728
  end
741
729
  end
742
730
 
743
- describe "Alternate user class" do
731
+ describe 'Alternate user class' do
744
732
  before do
745
- post "/mangs", {
746
- email: Faker::Internet.email,
747
- password: "secret123",
748
- password_confirmation: "secret123",
749
- confirm_success_url: Faker::Internet.url
750
- }
733
+ post '/mangs',
734
+ params: { email: Faker::Internet.email,
735
+ password: 'secret123',
736
+ password_confirmation: 'secret123',
737
+ confirm_success_url: Faker::Internet.url }
751
738
 
752
739
  @resource = assigns(:resource)
753
740
  @data = JSON.parse(response.body)
754
741
  @mail = ActionMailer::Base.deliveries.last
755
742
  end
756
743
 
757
- test "request should be successful" do
744
+ test 'request should be successful' do
758
745
  assert_equal 200, response.status
759
746
  end
760
747
 
761
- test "use should be a Mang" do
762
- assert_equal "Mang", @resource.class.name
748
+ test 'use should be a Mang' do
749
+ assert_equal 'Mang', @resource.class.name
763
750
  end
764
751
 
765
- test "Mang should be destroyed" do
752
+ test 'Mang should be destroyed' do
766
753
  @resource.skip_confirmation!
767
754
  @resource.save!
768
755
  @auth_headers = @resource.create_new_auth_token
@@ -771,24 +758,25 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
771
758
  # ensure request is not treated as batch request
772
759
  age_token(@resource, @client_id)
773
760
 
774
- xhr :delete, "/mangs", {}, @auth_headers
761
+ delete '/mangs',
762
+ params: {},
763
+ headers: @auth_headers
775
764
 
776
765
  assert_equal 200, response.status
777
766
  refute Mang.where(id: @resource.id).first
778
767
  end
779
768
  end
780
769
 
781
- describe "Passing client config name" do
770
+ describe 'Passing client config name' do
782
771
  before do
783
772
  @config_name = 'altUser'
784
773
 
785
- post "/mangs", {
786
- email: Faker::Internet.email,
787
- password: "secret123",
788
- password_confirmation: "secret123",
789
- confirm_success_url: Faker::Internet.url,
790
- config_name: @config_name
791
- }
774
+ post '/mangs',
775
+ params: { email: Faker::Internet.email,
776
+ password: 'secret123',
777
+ password_confirmation: 'secret123',
778
+ confirm_success_url: Faker::Internet.url,
779
+ config_name: @config_name }
792
780
 
793
781
  @resource = assigns(:resource)
794
782
  @data = JSON.parse(response.body)
@@ -808,70 +796,66 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
808
796
 
809
797
  describe 'Excluded :registrations module' do
810
798
  test 'UnregisterableUser should not be able to access registration routes' do
811
- assert_raises(ActionController::RoutingError) {
812
- post '/unregisterable_user_auth', {
813
- email: Faker::Internet.email,
814
- password: "secret123",
815
- password_confirmation: "secret123",
816
- confirm_success_url: Faker::Internet.url
817
- }
818
- }
799
+ assert_raises(ActionController::RoutingError) do
800
+ post '/unregisterable_user_auth',
801
+ params: { email: Faker::Internet.email,
802
+ password: 'secret123',
803
+ password_confirmation: 'secret123',
804
+ confirm_success_url: Faker::Internet.url }
805
+ end
819
806
  end
820
807
  end
821
808
 
822
- describe "Skipped confirmation" do
809
+ describe 'Skipped confirmation' do
823
810
  setup do
824
811
  User.set_callback(:create, :before, :skip_confirmation!)
825
812
 
826
- post "/auth", {
827
- email: Faker::Internet.email,
828
- password: "secret123",
829
- password_confirmation: "secret123",
830
- confirm_success_url: Faker::Internet.url
831
- }
813
+ post '/auth',
814
+ params: { email: Faker::Internet.email,
815
+ password: 'secret123',
816
+ password_confirmation: 'secret123',
817
+ confirm_success_url: Faker::Internet.url }
832
818
 
833
819
  @resource = assigns(:resource)
834
- @token = response.headers["access-token"]
835
- @client_id = response.headers["client"]
820
+ @token = response.headers['access-token']
821
+ @client_id = response.headers['client']
836
822
  end
837
823
 
838
824
  teardown do
839
825
  User.skip_callback(:create, :before, :skip_confirmation!)
840
826
  end
841
827
 
842
- test "user was created" do
828
+ test 'user was created' do
843
829
  assert @resource
844
830
  end
845
831
 
846
- test "user was confirmed" do
832
+ test 'user was confirmed' do
847
833
  assert @resource.confirmed?
848
834
  end
849
835
 
850
- test "auth headers were returned in response" do
851
- assert response.headers["access-token"]
852
- assert response.headers["token-type"]
853
- assert response.headers["client"]
854
- assert response.headers["expiry"]
855
- assert response.headers["uid"]
836
+ test 'auth headers were returned in response' do
837
+ assert response.headers['access-token']
838
+ assert response.headers['token-type']
839
+ assert response.headers['client']
840
+ assert response.headers['expiry']
841
+ assert response.headers['uid']
856
842
  end
857
843
 
858
- test "response token is valid" do
844
+ test 'response token is valid' do
859
845
  assert @resource.valid_token?(@token, @client_id)
860
846
  end
861
847
  end
862
848
 
863
-
864
849
  describe 'User with only :database_authenticatable and :registerable included' do
865
850
  setup do
866
851
  @mails_sent = ActionMailer::Base.deliveries.count
867
852
 
868
- post '/only_email_auth', {
869
- email: Faker::Internet.email,
870
- password: "secret123",
871
- password_confirmation: "secret123",
872
- confirm_success_url: Faker::Internet.url,
873
- unpermitted_param: '(x_x)'
874
- }
853
+ post '/only_email_auth',
854
+ params: { email: Faker::Internet.email,
855
+ password: 'secret123',
856
+ password_confirmation: 'secret123',
857
+ confirm_success_url: Faker::Internet.url,
858
+ unpermitted_param: '(x_x)' }
875
859
 
876
860
  @resource = assigns(:resource)
877
861
  @data = JSON.parse(response.body)