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
@@ -8,7 +8,7 @@ require 'test_helper'
8
8
 
9
9
  class DemoMangControllerTest < ActionDispatch::IntegrationTest
10
10
  describe DemoMangController do
11
- describe "Token access" do
11
+ describe 'Token access' do
12
12
  before do
13
13
  @resource = mangs(:confirmed_email_user)
14
14
  @resource.skip_confirmation!
@@ -26,7 +26,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
26
26
  # ensure that request is not treated as batch request
27
27
  age_token(@resource, @client_id)
28
28
 
29
- get '/demo/members_only_mang', {}, @auth_headers
29
+ get '/demo/members_only_mang',
30
+ params: {},
31
+ headers: @auth_headers
30
32
 
31
33
  @resp_token = response.headers['access-token']
32
34
  @resp_client_id = response.headers['client']
@@ -46,6 +48,10 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
46
48
  it 'should not define current_user' do
47
49
  refute_equal @resource, @controller.current_user
48
50
  end
51
+
52
+ it 'should define render_authenticate_error' do
53
+ assert @controller.methods.include?(:render_authenticate_error)
54
+ end
49
55
  end
50
56
 
51
57
  it 'should return success status' do
@@ -74,14 +80,16 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
74
80
  # ensure that request is not treated as batch request
75
81
  age_token(@resource, @client_id)
76
82
 
77
- get '/demo/members_only_mang', {}, @auth_headers.merge({'access-token' => @resp_token})
83
+ get '/demo/members_only_mang',
84
+ params: {},
85
+ headers: @auth_headers.merge('access-token' => @resp_token)
78
86
  end
79
87
 
80
88
  it 'should not treat this request as a batch request' do
81
89
  refute assigns(:is_batch_request)
82
90
  end
83
91
 
84
- it "should allow a new request to be made using new token" do
92
+ it 'should allow a new request to be made using new token' do
85
93
  assert_equal 200, response.status
86
94
  end
87
95
  end
@@ -89,7 +97,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
89
97
 
90
98
  describe 'failed request' do
91
99
  before do
92
- get '/demo/members_only_mang', {}, @auth_headers.merge({'access-token' => "bogus"})
100
+ get '/demo/members_only_mang',
101
+ params: {},
102
+ headers: @auth_headers.merge('access-token' => 'bogus')
93
103
  end
94
104
 
95
105
  it 'should not return any auth headers' do
@@ -107,7 +117,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
107
117
  @resource.reload
108
118
  age_token(@resource, @client_id)
109
119
 
110
- get '/demo/members_only_mang', {}, @auth_headers
120
+ get '/demo/members_only_mang',
121
+ params: {},
122
+ headers: @auth_headers
111
123
 
112
124
  @first_is_batch_request = assigns(:is_batch_request)
113
125
  @first_user = assigns(:resource).dup
@@ -118,7 +130,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
118
130
  age_token(@resource, @client_id)
119
131
 
120
132
  # use expired auth header
121
- get '/demo/members_only_mang', {}, @auth_headers
133
+ get '/demo/members_only_mang',
134
+ params: {},
135
+ headers: @auth_headers
122
136
 
123
137
  @second_is_batch_request = assigns(:is_batch_request)
124
138
  @second_user = assigns(:resource).dup
@@ -164,15 +178,19 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
164
178
  describe 'success' do
165
179
  before do
166
180
  age_token(@resource, @client_id)
167
- #request.headers.merge!(@auth_headers)
181
+ # request.headers.merge!(@auth_headers)
168
182
 
169
- get '/demo/members_only_mang', {}, @auth_headers
183
+ get '/demo/members_only_mang',
184
+ params: {},
185
+ headers: @auth_headers
170
186
 
171
187
  @first_is_batch_request = assigns(:is_batch_request)
172
188
  @first_user = assigns(:resource)
173
189
  @first_access_token = response.headers['access-token']
174
190
 
175
- get '/demo/members_only_mang', {}, @auth_headers
191
+ get '/demo/members_only_mang',
192
+ params: {},
193
+ headers: @auth_headers
176
194
 
177
195
  @second_is_batch_request = assigns(:is_batch_request)
178
196
  @second_user = assigns(:resource)
@@ -196,7 +214,7 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
196
214
  end
197
215
 
198
216
  it 'should not return auth headers for second (batched) requests' do
199
- refute @second_access_token
217
+ assert_equal ' ', @second_access_token
200
218
  end
201
219
  end
202
220
 
@@ -205,7 +223,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
205
223
  @resource.reload
206
224
  age_token(@resource, @client_id)
207
225
 
208
- get '/demo/members_only_mang', {}, @auth_headers
226
+ get '/demo/members_only_mang',
227
+ params: {},
228
+ headers: @auth_headers
209
229
 
210
230
  @first_is_batch_request = assigns(:is_batch_request)
211
231
  @first_user = assigns(:resource).dup
@@ -216,7 +236,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
216
236
  age_token(@resource, @client_id)
217
237
 
218
238
  # use expired auth header
219
- get '/demo/members_only_mang', {}, @auth_headers
239
+ get '/demo/members_only_mang',
240
+ params: {},
241
+ headers: @auth_headers
220
242
 
221
243
  @second_is_batch_request = assigns(:is_batch_request)
222
244
  @second_user = assigns(:resource)
@@ -233,7 +255,7 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
233
255
  end
234
256
 
235
257
  it 'should not treat first request as batch request' do
236
- refute @secord_is_batch_request
258
+ refute @second_is_batch_request
237
259
  end
238
260
 
239
261
  it 'should return auth headers from the first request' do
@@ -241,7 +263,7 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
241
263
  end
242
264
 
243
265
  it 'should not treat second request as batch request' do
244
- refute @secord_is_batch_request
266
+ refute @second_is_batch_request
245
267
  end
246
268
 
247
269
  it 'should not return auth headers from the second request' do
@@ -260,4 +282,3 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest
260
282
  end
261
283
  end
262
284
  end
263
-
@@ -9,7 +9,7 @@ require 'test_helper'
9
9
  class DemoUserControllerTest < ActionDispatch::IntegrationTest
10
10
  include Warden::Test::Helpers
11
11
  describe DemoUserController do
12
- describe "Token access" do
12
+ describe 'Token access' do
13
13
  before do
14
14
  @resource = users(:confirmed_email_user)
15
15
  @resource.skip_confirmation!
@@ -27,7 +27,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
27
27
  # ensure that request is not treated as batch request
28
28
  age_token(@resource, @client_id)
29
29
 
30
- get '/demo/members_only', {}, @auth_headers
30
+ get '/demo/members_only',
31
+ params: {},
32
+ headers: @auth_headers
31
33
 
32
34
  @resp_token = response.headers['access-token']
33
35
  @resp_client_id = response.headers['client']
@@ -47,6 +49,10 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
47
49
  it 'should not define current_mang' do
48
50
  refute_equal @resource, @controller.current_mang
49
51
  end
52
+
53
+ it 'should define render_authenticate_error' do
54
+ assert @controller.methods.include?(:render_authenticate_error)
55
+ end
50
56
  end
51
57
 
52
58
  it 'should return success status' do
@@ -75,14 +81,16 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
75
81
  # ensure that request is not treated as batch request
76
82
  age_token(@resource, @client_id)
77
83
 
78
- get '/demo/members_only', {}, @auth_headers.merge({'access-token' => @resp_token})
84
+ get '/demo/members_only',
85
+ params: {},
86
+ headers: @auth_headers.merge('access-token' => @resp_token)
79
87
  end
80
88
 
81
89
  it 'should not treat this request as a batch request' do
82
90
  refute assigns(:is_batch_request)
83
91
  end
84
92
 
85
- it "should allow a new request to be made using new token" do
93
+ it 'should allow a new request to be made using new token' do
86
94
  assert_equal 200, response.status
87
95
  end
88
96
  end
@@ -90,7 +98,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
90
98
 
91
99
  describe 'failed request' do
92
100
  before do
93
- get '/demo/members_only', {}, @auth_headers.merge({'access-token' => "bogus"})
101
+ get '/demo/members_only',
102
+ params: {},
103
+ headers: @auth_headers.merge('access-token' => 'bogus')
94
104
  end
95
105
 
96
106
  it 'should not return any auth headers' do
@@ -108,7 +118,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
108
118
  @resource.reload
109
119
  age_token(@resource, @client_id)
110
120
 
111
- get '/demo/members_only', {}, @auth_headers
121
+ get '/demo/members_only',
122
+ params: {},
123
+ headers: @auth_headers
112
124
 
113
125
  @first_is_batch_request = assigns(:is_batch_request)
114
126
  @first_user = assigns(:resource).dup
@@ -119,7 +131,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
119
131
  age_token(@resource, @client_id)
120
132
 
121
133
  # use expired auth header
122
- get '/demo/members_only', {}, @auth_headers
134
+ get '/demo/members_only',
135
+ params: {},
136
+ headers: @auth_headers
123
137
 
124
138
  @second_is_batch_request = assigns(:is_batch_request)
125
139
  @second_user = assigns(:resource).dup
@@ -165,15 +179,19 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
165
179
  describe 'success' do
166
180
  before do
167
181
  age_token(@resource, @client_id)
168
- #request.headers.merge!(@auth_headers)
182
+ # request.headers.merge!(@auth_headers)
169
183
 
170
- get '/demo/members_only', {}, @auth_headers
184
+ get '/demo/members_only',
185
+ params: {},
186
+ headers: @auth_headers
171
187
 
172
188
  @first_is_batch_request = assigns(:is_batch_request)
173
189
  @first_user = assigns(:resource)
174
190
  @first_access_token = response.headers['access-token']
175
191
 
176
- get '/demo/members_only', {}, @auth_headers
192
+ get '/demo/members_only',
193
+ params: {},
194
+ headers: @auth_headers
177
195
 
178
196
  @second_is_batch_request = assigns(:is_batch_request)
179
197
  @second_user = assigns(:resource)
@@ -197,7 +215,7 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
197
215
  end
198
216
 
199
217
  it 'should not return auth headers for second (batched) requests' do
200
- refute @second_access_token
218
+ assert_equal ' ', @second_access_token
201
219
  end
202
220
  end
203
221
 
@@ -206,14 +224,18 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
206
224
  @resource.reload
207
225
  age_token(@resource, @client_id)
208
226
 
209
- get '/demo/members_only', {}, @auth_headers
227
+ get '/demo/members_only',
228
+ params: {},
229
+ headers: @auth_headers
210
230
 
211
231
  @first_is_batch_request = assigns(:is_batch_request)
212
232
  @first_user = assigns(:resource).dup
213
233
  @first_access_token = response.headers['access-token']
214
234
  @first_response_status = response.status
215
235
 
216
- get '/demo/members_only?unbatch=true', {}, @auth_headers
236
+ get '/demo/members_only?unbatch=true',
237
+ params: {},
238
+ headers: @auth_headers
217
239
 
218
240
  @second_is_batch_request = assigns(:is_batch_request)
219
241
  @second_user = assigns(:resource)
@@ -231,7 +253,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
231
253
  @resource.reload
232
254
  age_token(@resource, @client_id)
233
255
 
234
- get '/demo/members_only', {}, @auth_headers
256
+ get '/demo/members_only',
257
+ params: {},
258
+ headers: @auth_headers
235
259
 
236
260
  @first_is_batch_request = assigns(:is_batch_request)
237
261
  @first_user = assigns(:resource).dup
@@ -242,7 +266,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
242
266
  age_token(@resource, @client_id)
243
267
 
244
268
  # use expired auth header
245
- get '/demo/members_only', {}, @auth_headers
269
+ get '/demo/members_only',
270
+ params: {},
271
+ headers: @auth_headers
246
272
 
247
273
  @second_is_batch_request = assigns(:is_batch_request)
248
274
  @second_user = assigns(:resource)
@@ -259,7 +285,7 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
259
285
  end
260
286
 
261
287
  it 'should not treat first request as batch request' do
262
- refute @secord_is_batch_request
288
+ refute @second_is_batch_request
263
289
  end
264
290
 
265
291
  it 'should return auth headers from the first request' do
@@ -267,7 +293,7 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
267
293
  end
268
294
 
269
295
  it 'should not treat second request as batch request' do
270
- refute @secord_is_batch_request
296
+ refute @second_is_batch_request
271
297
  end
272
298
 
273
299
  it 'should not return auth headers from the second request' do
@@ -295,12 +321,12 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
295
321
  assert @resource.tokens.count > 1
296
322
 
297
323
  # password changed from new device
298
- @resource.update_attributes({
299
- password: 'newsecret123',
300
- password_confirmation: 'newsecret123'
301
- })
324
+ @resource.update_attributes(password: 'newsecret123',
325
+ password_confirmation: 'newsecret123')
302
326
 
303
- get '/demo/members_only', {}, @auth_headers
327
+ get '/demo/members_only',
328
+ params: {},
329
+ headers: @auth_headers
304
330
  end
305
331
 
306
332
  after do
@@ -316,14 +342,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
316
342
  end
317
343
 
318
344
  describe 'another device should not be able to login' do
319
-
320
345
  it 'should return forbidden status' do
321
- get '/demo/members_only', {}, @old_auth_headers
346
+ get '/demo/members_only',
347
+ params: {},
348
+ headers: @old_auth_headers
322
349
  assert 401, response.status
323
350
  end
324
-
325
351
  end
326
-
327
352
  end
328
353
 
329
354
  describe 'request including destroy of token' do
@@ -332,7 +357,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
332
357
  DeviseTokenAuth.change_headers_on_each_request = false
333
358
  age_token(@resource, @client_id)
334
359
 
335
- get '/demo/members_only_remove_token', {}, @auth_headers
360
+ get '/demo/members_only_remove_token',
361
+ params: {},
362
+ headers: @auth_headers
336
363
  end
337
364
 
338
365
  after do
@@ -347,7 +374,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
347
374
  describe 'when change_headers_on_each_request is set to true' do
348
375
  before do
349
376
  age_token(@resource, @client_id)
350
- get '/demo/members_only_remove_token', {}, @auth_headers
377
+ get '/demo/members_only_remove_token',
378
+ params: {},
379
+ headers: @auth_headers
351
380
  end
352
381
 
353
382
  it 'should not return auth-headers' do
@@ -364,7 +393,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
364
393
  client_id = auth_headers_modified['client']
365
394
  age_token(@resource, client_id)
366
395
 
367
- get '/demo/members_only', {}, auth_headers_modified
396
+ get '/demo/members_only',
397
+ params: {},
398
+ headers: auth_headers_modified
368
399
  @resp_token = response.headers['new-access-token']
369
400
  end
370
401
 
@@ -379,7 +410,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
379
410
  end
380
411
 
381
412
  describe 'enable_standard_devise_support' do
382
-
383
413
  before do
384
414
  @resource = users(:confirmed_email_user)
385
415
  @auth_headers = @resource.create_new_auth_token
@@ -391,10 +421,12 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
391
421
  @resource = users(:second_confirmed_email_user)
392
422
  @resource.skip_confirmation!
393
423
  @resource.save!
394
- login_as( @resource, :scope => :user)
424
+ login_as(@resource, scope: :user)
395
425
 
396
426
  # no auth headers sent, testing that warden authenticates correctly.
397
- get '/demo/members_only', {}, nil
427
+ get '/demo/members_only',
428
+ params: {},
429
+ headers: nil
398
430
 
399
431
  @resp_token = response.headers['access-token']
400
432
  @resp_client_id = response.headers['client']
@@ -415,14 +447,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
415
447
  refute_equal @resource, @controller.current_mang
416
448
  end
417
449
 
418
-
419
450
  it 'should increase the number of tokens by a factor of 2 up to 11' do
420
451
  @first_token = @resource.tokens.keys.first
421
452
 
422
453
  DeviseTokenAuth.max_number_of_devices = 11
423
454
  (1..10).each do |n|
424
- assert_equal [11, 2*n].min, @resource.reload.tokens.keys.length
425
- get '/demo/members_only', {}, nil
455
+ assert_equal [11, 2 * n].min, @resource.reload.tokens.keys.length
456
+ get '/demo/members_only', params: {}, headers: nil
426
457
  end
427
458
 
428
459
  assert_not_includes @resource.reload.tokens.keys, @first_token
@@ -455,9 +486,11 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
455
486
  @resource = users(:second_confirmed_email_user)
456
487
  @resource.skip_confirmation!
457
488
  @resource.save!
458
- login_as( @resource, :scope => :user)
489
+ login_as(@resource, scope: :user)
459
490
 
460
- get '/demo/members_only', {}, @auth_headers
491
+ get '/demo/members_only',
492
+ params: {},
493
+ headers: @auth_headers
461
494
 
462
495
  @resp_token = response.headers['access-token']
463
496
  @resp_client_id = response.headers['client']
@@ -507,7 +540,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
507
540
  refute_equal @resp_uid, @auth_headers['uid']
508
541
  end
509
542
  end
510
-
511
543
  end
512
544
  end
513
545
  end
@@ -14,13 +14,11 @@ class DeviseTokenAuth::ConfirmationsControllerTest < ActionController::TestCase
14
14
  [token, client_config]
15
15
  end
16
16
 
17
- describe "Confirmation" do
17
+ describe 'Confirmation' do
18
18
  before do
19
19
  @redirect_url = Faker::Internet.url
20
20
  @new_user = users(:unconfirmed_email_user)
21
- @new_user.send_confirmation_instructions({
22
- redirect_url: @redirect_url
23
- })
21
+ @new_user.send_confirmation_instructions(redirect_url: @redirect_url)
24
22
  mail = ActionMailer::Base.deliveries.last
25
23
  @token, @client_config = token_and_client_config_from(mail.body)
26
24
  end
@@ -30,33 +28,52 @@ class DeviseTokenAuth::ConfirmationsControllerTest < ActionController::TestCase
30
28
  end
31
29
 
32
30
  test "should include config name as 'default' in confirmation link" do
33
- assert_equal "default", @client_config
31
+ assert_equal 'default', @client_config
34
32
  end
35
33
 
36
- test "should store token hash in user" do
34
+ test 'should store token hash in user' do
37
35
  assert @new_user.confirmation_token
38
36
  end
39
37
 
40
- describe "success" do
38
+ describe 'success' do
41
39
  before do
42
- xhr :get, :show, {confirmation_token: @token, redirect_url: @redirect_url}
40
+ get :show,
41
+ params: { confirmation_token: @token,
42
+ redirect_url: @redirect_url },
43
+ xhr: true
43
44
  @resource = assigns(:resource)
44
45
  end
45
46
 
46
- test "user should now be confirmed" do
47
+ test 'user should now be confirmed' do
47
48
  assert @resource.confirmed?
48
49
  end
49
50
 
50
- test "should redirect to success url" do
51
+ test 'should redirect to success url' do
51
52
  assert_redirected_to(/^#{@redirect_url}/)
52
53
  end
54
+
55
+ test 'the sign_in_count should be 1' do
56
+ assert @resource.sign_in_count == 1
57
+ end
58
+ test 'User shoud have the signed in info filled' do
59
+ assert @resource.current_sign_in_at?
60
+ end
61
+ test 'User shoud have the Last checkin filled' do
62
+ assert @resource.last_sign_in_at?
63
+ end
64
+
65
+ test 'user already confirmed' do
66
+ assert @resource.sign_in_count > 0 do
67
+ assert expiry == (Time.now + Time.now + 1.second).to_i
68
+ end
69
+ end
53
70
  end
54
71
 
55
- describe "failure" do
56
- test "user should not be confirmed" do
57
- assert_raises(ActionController::RoutingError) {
58
- xhr :get, :show, {confirmation_token: "bogus"}
59
- }
72
+ describe 'failure' do
73
+ test 'user should not be confirmed' do
74
+ assert_raises(ActionController::RoutingError) do
75
+ get :show, params: { confirmation_token: 'bogus' }
76
+ end
60
77
  @resource = assigns(:resource)
61
78
  refute @resource.confirmed?
62
79
  end
@@ -64,7 +81,7 @@ class DeviseTokenAuth::ConfirmationsControllerTest < ActionController::TestCase
64
81
  end
65
82
 
66
83
  # test with non-standard user class
67
- describe "Alternate user model" do
84
+ describe 'Alternate user model' do
68
85
  setup do
69
86
  @request.env['devise.mapping'] = Devise.mappings[:mang]
70
87
  end
@@ -74,7 +91,7 @@ class DeviseTokenAuth::ConfirmationsControllerTest < ActionController::TestCase
74
91
  end
75
92
 
76
93
  before do
77
- @config_name = "altUser"
94
+ @config_name = 'altUser'
78
95
  @new_user = mangs(:unconfirmed_email_user)
79
96
 
80
97
  @new_user.send_confirmation_instructions(client_config: @config_name)
@@ -87,22 +104,23 @@ class DeviseTokenAuth::ConfirmationsControllerTest < ActionController::TestCase
87
104
  assert @token
88
105
  end
89
106
 
90
- test "should include config name in confirmation link" do
107
+ test 'should include config name in confirmation link' do
91
108
  assert_equal @config_name, @client_config
92
109
  end
93
110
 
94
- test "should store token hash in user" do
111
+ test 'should store token hash in user' do
95
112
  assert @new_user.confirmation_token
96
113
  end
97
114
 
98
- describe "success" do
115
+ describe 'success' do
99
116
  before do
100
117
  @redirect_url = Faker::Internet.url
101
- xhr :get, :show, {confirmation_token: @token, redirect_url: @redirect_url}
118
+ get :show, params: { confirmation_token: @token,
119
+ redirect_url: @redirect_url }
102
120
  @resource = assigns(:resource)
103
121
  end
104
122
 
105
- test "user should now be confirmed" do
123
+ test 'user should now be confirmed' do
106
124
  assert @resource.confirmed?
107
125
  end
108
126
  end