devise_g5_authenticatable 0.3.0 → 1.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +29 -7
  6. data/Appraisals +21 -0
  7. data/CHANGELOG.md +24 -0
  8. data/Gemfile +11 -7
  9. data/README.md +6 -6
  10. data/Rakefile +6 -5
  11. data/app/controllers/devise_g5_authenticatable/registrations_controller.rb +3 -0
  12. data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +9 -5
  13. data/config/initializers/devise_g5_authenticatable.rb +2 -0
  14. data/devise_g5_authenticatable.gemspec +6 -5
  15. data/gemfiles/rails_4.1.gemfile +26 -0
  16. data/gemfiles/rails_4.2.gemfile +26 -0
  17. data/gemfiles/rails_5.0.gemfile +26 -0
  18. data/gemfiles/rails_5.1.gemfile +26 -0
  19. data/lib/devise_g5_authenticatable/controllers/helpers.rb +5 -0
  20. data/lib/devise_g5_authenticatable/controllers/url_helpers.rb +3 -0
  21. data/lib/devise_g5_authenticatable/engine.rb +4 -1
  22. data/lib/devise_g5_authenticatable/g5/auth_password_validator.rb +6 -1
  23. data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +16 -15
  24. data/lib/devise_g5_authenticatable/g5/auth_user_updater.rb +11 -5
  25. data/lib/devise_g5_authenticatable/g5/user_exporter.rb +11 -6
  26. data/lib/devise_g5_authenticatable/g5.rb +2 -0
  27. data/lib/devise_g5_authenticatable/hooks/g5_authenticatable.rb +8 -3
  28. data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +38 -26
  29. data/lib/devise_g5_authenticatable/models/protected_attributes.rb +11 -2
  30. data/lib/devise_g5_authenticatable/omniauth.rb +8 -2
  31. data/lib/devise_g5_authenticatable/routes.rb +48 -35
  32. data/lib/devise_g5_authenticatable/version.rb +3 -1
  33. data/lib/devise_g5_authenticatable.rb +4 -1
  34. data/spec/controllers/helpers_spec.rb +54 -49
  35. data/spec/controllers/sessions_controller_spec.rb +67 -39
  36. data/spec/controllers/url_helpers_spec.rb +78 -78
  37. data/spec/dummy/app/views/{anonymous → devise}/new.html.erb +0 -0
  38. data/spec/dummy/config/environments/test.rb +20 -4
  39. data/spec/dummy/config/initializers/devise.rb +5 -1
  40. data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
  41. data/spec/dummy/db/migrate/20131230235849_devise_create_users.rb +3 -1
  42. data/spec/dummy/db/migrate/20140102213131_drop_database_authenticatable.rb +3 -1
  43. data/spec/dummy/db/migrate/20140103032308_drop_recoverable.rb +3 -1
  44. data/spec/dummy/db/migrate/20140103042329_drop_rememberable.rb +3 -1
  45. data/spec/dummy/db/migrate/20140103174810_add_omniauth_columns_to_users.rb +3 -1
  46. data/spec/dummy/db/migrate/20140103191601_add_email_back_to_user.rb +3 -1
  47. data/spec/dummy/db/migrate/20140113202948_devise_create_admins.rb +3 -1
  48. data/spec/dummy/db/migrate/20140113233821_add_provider_and_uid_to_admins.rb +3 -1
  49. data/spec/dummy/db/schema.rb +29 -29
  50. data/spec/factories/admin.rb +2 -0
  51. data/spec/factories/user.rb +2 -0
  52. data/spec/features/edit_registration_spec.rb +22 -13
  53. data/spec/features/registration_spec.rb +13 -8
  54. data/spec/features/sign_in_spec.rb +4 -2
  55. data/spec/features/sign_out_spec.rb +4 -2
  56. data/spec/features/token_validation_spec.rb +24 -14
  57. data/spec/g5/auth_password_validator_spec.rb +28 -15
  58. data/spec/g5/auth_user_creator_spec.rb +29 -22
  59. data/spec/g5/auth_user_updater_spec.rb +23 -16
  60. data/spec/g5/user_exporter_spec.rb +36 -31
  61. data/spec/models/g5_authenticatable_spec.rb +78 -38
  62. data/spec/models/protected_attributes_spec.rb +24 -19
  63. data/spec/rails_helper.rb +46 -0
  64. data/spec/routing/registrations_routing_spec.rb +43 -27
  65. data/spec/routing/sessions_routing_spec.rb +46 -29
  66. data/spec/spec_helper.rb +93 -27
  67. data/spec/support/controller_test_helpers.rb +15 -0
  68. data/spec/support/devise.rb +9 -1
  69. data/spec/support/shared_contexts/custom_router.rb +16 -0
  70. data/spec/support/shared_contexts/oauth_error.rb +4 -2
  71. data/spec/support/shared_contexts/rake.rb +10 -4
  72. data/spec/support/shared_examples/registration_error.rb +3 -1
  73. data/spec/support/{user_feature_methods.rb → user_omniauth_methods.rb} +9 -5
  74. data/spec/tasks/export_users_spec.rb +5 -3
  75. metadata +30 -26
  76. data/circle.yml +0 -4
  77. data/spec/support/omniauth.rb +0 -3
@@ -1,12 +1,17 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe Devise::G5::AuthUserUpdater do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Devise::G5::AuthUserUpdater do
4
6
  let(:updater) { described_class.new(model) }
5
7
 
6
- let(:auth_client) { double(:g5_authentication_client, update_user: auth_user) }
8
+ let(:auth_client) do
9
+ double(:g5_authentication_client, update_user: auth_user)
10
+ end
7
11
  let(:auth_user) { double(:auth_user, id: model.uid, email: model.email) }
8
12
  before do
9
- allow(G5AuthenticationClient::Client).to receive(:new).and_return(auth_client)
13
+ allow(G5AuthenticationClient::Client).to receive(:new)
14
+ .and_return(auth_client)
10
15
  end
11
16
 
12
17
  let(:model) { create(:user, updated_by: updated_by) }
@@ -28,7 +33,6 @@ describe Devise::G5::AuthUserUpdater do
28
33
  before { model.email = updated_email }
29
34
  let(:updated_email) { 'updated.email@test.host' }
30
35
 
31
-
32
36
  context 'when user has been updated by another user' do
33
37
  let(:updated_by) { create(:user) }
34
38
 
@@ -36,13 +40,13 @@ describe Devise::G5::AuthUserUpdater do
36
40
  before { update }
37
41
 
38
42
  it 'should use the token for updated_by to call g5 auth' do
39
- expect(G5AuthenticationClient::Client).to have_received(:new).
40
- with(access_token: updated_by.g5_access_token)
43
+ expect(G5AuthenticationClient::Client).to have_received(:new)
44
+ .with(access_token: updated_by.g5_access_token)
41
45
  end
42
46
 
43
47
  it 'should update the email' do
44
- expect(auth_client).to have_received(:update_user).
45
- with(hash_including(email: updated_email))
48
+ expect(auth_client).to have_received(:update_user)
49
+ .with(hash_including(email: updated_email))
46
50
  end
47
51
 
48
52
  it 'should reset the password' do
@@ -64,7 +68,7 @@ describe Devise::G5::AuthUserUpdater do
64
68
  end
65
69
 
66
70
  it 'should raise an exception' do
67
- expect { update }.to raise_error
71
+ expect { update }.to raise_error('Error!')
68
72
  end
69
73
  end
70
74
  end
@@ -73,8 +77,8 @@ describe Devise::G5::AuthUserUpdater do
73
77
  before { update }
74
78
 
75
79
  it 'should use the user token to call g5 auth' do
76
- expect(G5AuthenticationClient::Client).to have_received(:new).
77
- with(access_token: model.g5_access_token)
80
+ expect(G5AuthenticationClient::Client).to have_received(:new)
81
+ .with(access_token: model.g5_access_token)
78
82
  end
79
83
  end
80
84
  end
@@ -91,14 +95,17 @@ describe Devise::G5::AuthUserUpdater do
91
95
  before { update }
92
96
 
93
97
  it 'should update the password' do
94
- expect(auth_client).to have_received(:update_user).
95
- with(hash_including(password: updated_password))
98
+ expect(auth_client).to have_received(:update_user)
99
+ .with(hash_including(password: updated_password))
96
100
  update
97
101
  end
98
102
 
99
103
  it 'should update the password_confirmation' do
100
- expect(auth_client).to have_received(:update_user).
101
- with(hash_including(password_confirmation: updated_password_confirmation))
104
+ updated_attribute = {
105
+ password_confirmation: updated_password_confirmation
106
+ }
107
+ expect(auth_client).to have_received(:update_user)
108
+ .with(hash_including(updated_attribute))
102
109
  end
103
110
 
104
111
  it 'should reset the password' do
@@ -1,14 +1,16 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe G5::UserExporter do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe G5::UserExporter do
4
6
  let(:exporter) { G5::UserExporter.new(options) }
5
7
 
6
8
  let(:options) do
7
- {client_id: 'my_client_id',
8
- client_secret: 'soopersekrit',
9
- redirect_uri: 'https://app.host/my/callback',
10
- endpoint: 'https://auth.host',
11
- authorization_code: 'abc123'}
9
+ { client_id: 'my_client_id',
10
+ client_secret: 'soopersekrit',
11
+ redirect_uri: 'https://app.host/my/callback',
12
+ endpoint: 'https://auth.host',
13
+ authorization_code: 'abc123' }
12
14
  end
13
15
 
14
16
  describe '#export' do
@@ -31,55 +33,56 @@ describe G5::UserExporter do
31
33
  let(:auth_user) { double(:auth_user, id: uid, email: email) }
32
34
  let(:auth_client) { double(:auth_client, create_user: auth_user) }
33
35
  before do
34
- allow(G5AuthenticationClient::Client).to receive(:new).and_return(auth_client)
36
+ allow(G5AuthenticationClient::Client).to receive(:new)
37
+ .and_return(auth_client)
35
38
  end
36
39
 
37
40
  it 'should initialize the auth client with the correct client_id' do
38
- expect(G5AuthenticationClient::Client).to receive(:new).
39
- with(hash_including(client_id: options[:client_id])).
40
- and_return(auth_client)
41
+ expect(G5AuthenticationClient::Client).to receive(:new)
42
+ .with(hash_including(client_id: options[:client_id]))
43
+ .and_return(auth_client)
41
44
  export
42
45
  end
43
46
 
44
47
  it 'should initialize the auth client with the correct client_secret' do
45
- expect(G5AuthenticationClient::Client).to receive(:new).
46
- with(hash_including(client_secret: options[:client_secret])).
47
- and_return(auth_client)
48
+ expect(G5AuthenticationClient::Client).to receive(:new)
49
+ .with(hash_including(client_secret: options[:client_secret]))
50
+ .and_return(auth_client)
48
51
  export
49
52
  end
50
53
 
51
54
  it 'should initialize the auth client with the correct redirect_uri' do
52
- expect(G5AuthenticationClient::Client).to receive(:new).
53
- with(hash_including(redirect_uri: options[:redirect_uri])).
54
- and_return(auth_client)
55
+ expect(G5AuthenticationClient::Client).to receive(:new)
56
+ .with(hash_including(redirect_uri: options[:redirect_uri]))
57
+ .and_return(auth_client)
55
58
  export
56
59
  end
57
60
 
58
61
  it 'should initialize the auth client with the correct endpoint' do
59
- expect(G5AuthenticationClient::Client).to receive(:new).
60
- with(hash_including(endpoint: options[:endpoint])).
61
- and_return(auth_client)
62
+ expect(G5AuthenticationClient::Client).to receive(:new)
63
+ .with(hash_including(endpoint: options[:endpoint]))
64
+ .and_return(auth_client)
62
65
  export
63
66
  end
64
67
 
65
- it 'should initialize the auth client with the correct authorization code' do
66
- expect(G5AuthenticationClient::Client).to receive(:new).
67
- with(hash_including(authorization_code: options[:authorization_code])).
68
- and_return(auth_client)
68
+ it 'initializes the auth client with the correct authorization code' do
69
+ expect(G5AuthenticationClient::Client).to receive(:new)
70
+ .with(hash_including(authorization_code: options[:authorization_code]))
71
+ .and_return(auth_client)
69
72
  export
70
73
  end
71
74
 
72
75
  it 'should create the auth user with the correct email' do
73
- expect(auth_client).to receive(:create_user).
74
- with(hash_including(email: email)).
75
- and_return(auth_user)
76
+ expect(auth_client).to receive(:create_user)
77
+ .with(hash_including(email: email))
78
+ .and_return(auth_user)
76
79
  export
77
80
  end
78
81
 
79
82
  it 'should create the auth user with the correct default password' do
80
- expect(auth_client).to receive(:create_user).
81
- with(hash_including(password: encrypted_password)).
82
- and_return(auth_user)
83
+ expect(auth_client).to receive(:create_user)
84
+ .with(hash_including(password: encrypted_password))
85
+ .and_return(auth_user)
83
86
  export
84
87
  end
85
88
 
@@ -99,7 +102,9 @@ describe G5::UserExporter do
99
102
  end
100
103
 
101
104
  it 'should return the SQL update statement with the encrypted password' do
102
- expect(export).to match(/update users set encrypted_password='#{encrypted_password}' where id=#{uid};/i)
105
+ expect(export).to match(
106
+ /update users set encrypted_password='#{encrypted_password}' where id=#{uid};/i
107
+ )
103
108
  end
104
109
  end
105
110
  end
@@ -1,11 +1,13 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe Devise::Models::G5Authenticatable do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Devise::Models::G5Authenticatable do
4
6
  subject { model }
5
7
 
6
8
  let(:model_class) { User }
7
9
  let(:model) { model_class.new(attributes) }
8
- let(:attributes) { Hash.new }
10
+ let(:attributes) { {} }
9
11
 
10
12
  describe '#save!' do
11
13
  subject(:save) { model.save! }
@@ -34,7 +36,8 @@ describe Devise::Models::G5Authenticatable do
34
36
  let(:auth_id) { 1 }
35
37
 
36
38
  before do
37
- allow(Devise::G5::AuthUserCreator).to receive(:new).and_return(auth_user_creator)
39
+ allow(Devise::G5::AuthUserCreator).to receive(:new)
40
+ .and_return(auth_user_creator)
38
41
  end
39
42
 
40
43
  context 'when model is valid' do
@@ -100,7 +103,8 @@ describe Devise::Models::G5Authenticatable do
100
103
  let(:error_body) { 'problems' }
101
104
 
102
105
  it 'should raise a RecordNotSaved error with the OAuth error code' do
103
- expect { save }. to raise_error(ActiveRecord::RecordNotSaved, error_code)
106
+ expect { save }.to raise_error(ActiveRecord::RecordNotSaved,
107
+ error_code)
104
108
  end
105
109
  end
106
110
 
@@ -109,7 +113,8 @@ describe Devise::Models::G5Authenticatable do
109
113
  let(:error_message) { 'problems' }
110
114
 
111
115
  it 'should raise a RecordNotSaved error' do
112
- expect { save }.to raise_error(ActiveRecord::RecordNotSaved, error_message)
116
+ expect { save }.to raise_error(ActiveRecord::RecordNotSaved,
117
+ error_message)
113
118
  end
114
119
  end
115
120
  end
@@ -122,7 +127,8 @@ describe Devise::Models::G5Authenticatable do
122
127
  let(:auth_user) { double(:auth_user, id: auth_id) }
123
128
  let(:auth_id) { 'remote-auth-id-42' }
124
129
  before do
125
- allow(Devise::G5::AuthUserUpdater).to receive(:new).and_return(auth_user_updater)
130
+ allow(Devise::G5::AuthUserUpdater).to receive(:new)
131
+ .and_return(auth_user_updater)
126
132
  end
127
133
 
128
134
  context 'with successful auth user update' do
@@ -144,7 +150,7 @@ describe Devise::Models::G5Authenticatable do
144
150
  let(:error_message) { 'problems' }
145
151
 
146
152
  it 'should raise an error' do
147
- expect { save }.to raise_error
153
+ expect { save }.to raise_error(error_message)
148
154
  end
149
155
  end
150
156
  end
@@ -168,7 +174,10 @@ describe Devise::Models::G5Authenticatable do
168
174
  let(:updated_email) { 'update@email.com' }
169
175
 
170
176
  let(:auth_updater) { double(:auth_user_updater, update: true) }
171
- before { allow(Devise::G5::AuthUserUpdater).to receive(:new).and_return(auth_updater) }
177
+ before do
178
+ allow(Devise::G5::AuthUserUpdater).to receive(:new)
179
+ .and_return(auth_updater)
180
+ end
172
181
 
173
182
  let(:password_validator) { double(:auth_password_validator) }
174
183
  before do
@@ -178,7 +187,9 @@ describe Devise::Models::G5Authenticatable do
178
187
  end
179
188
 
180
189
  context 'with valid current password' do
181
- before { allow(password_validator).to receive(:valid_password?).and_return(true) }
190
+ before do
191
+ allow(password_validator).to receive(:valid_password?).and_return(true)
192
+ end
182
193
 
183
194
  before { update_with_password }
184
195
 
@@ -218,7 +229,9 @@ describe Devise::Models::G5Authenticatable do
218
229
  end
219
230
 
220
231
  context 'with invalid current password' do
221
- before { allow(password_validator).to receive(:valid_password?).and_return(false) }
232
+ before do
233
+ allow(password_validator).to receive(:valid_password?).and_return(false)
234
+ end
222
235
 
223
236
  before { update_with_password }
224
237
 
@@ -284,9 +297,12 @@ describe Devise::Models::G5Authenticatable do
284
297
  let(:model) { create(:user) }
285
298
  let(:password) { 'foobarbaz' }
286
299
 
287
- let(:password_validator) { double(:password_validator, valid_password?: valid) }
300
+ let(:password_validator) do
301
+ double(:password_validator, valid_password?: valid)
302
+ end
288
303
  before do
289
- allow(Devise::G5::AuthPasswordValidator).to receive(:new).and_return(password_validator)
304
+ allow(Devise::G5::AuthPasswordValidator).to receive(:new)
305
+ .and_return(password_validator)
290
306
  end
291
307
 
292
308
  before { valid_password? }
@@ -299,11 +315,13 @@ describe Devise::Models::G5Authenticatable do
299
315
  end
300
316
 
301
317
  it 'should initialize the validator with the model' do
302
- expect(Devise::G5::AuthPasswordValidator).to have_received(:new).with(model)
318
+ expect(Devise::G5::AuthPasswordValidator).to have_received(:new)
319
+ .with(model)
303
320
  end
304
321
 
305
322
  it 'should check the password against the auth server' do
306
- expect(password_validator).to have_received(:valid_password?).with(password)
323
+ expect(password_validator).to have_received(:valid_password?)
324
+ .with(password)
307
325
  end
308
326
  end
309
327
 
@@ -315,22 +333,27 @@ describe Devise::Models::G5Authenticatable do
315
333
  end
316
334
 
317
335
  it 'should initialize the validator with the model' do
318
- expect(Devise::G5::AuthPasswordValidator).to have_received(:new).with(model)
336
+ expect(Devise::G5::AuthPasswordValidator).to have_received(:new)
337
+ .with(model)
319
338
  end
320
339
 
321
340
  it 'should check the password against the auth server' do
322
- expect(password_validator).to have_received(:valid_password?).with(password)
341
+ expect(password_validator).to have_received(:valid_password?)
342
+ .with(password)
323
343
  end
324
344
  end
325
345
  end
326
346
 
327
347
  describe '.find_and_update_for_g5_oauth' do
328
- subject(:find_and_update) { model_class.find_and_update_for_g5_oauth(auth_data) }
348
+ subject(:find_and_update) do
349
+ model_class.find_and_update_for_g5_oauth(auth_data)
350
+ end
329
351
 
330
352
  let(:auth_data) do
331
353
  OmniAuth::AuthHash.new(provider: 'g5',
332
354
  uid: '123999',
333
- info: { name: 'Foo Bar', email: 'foo@bar.com' },
355
+ info: { name: 'Foo Bar',
356
+ email: 'foo@bar.com' },
334
357
  credentials: { token: 'abc123' })
335
358
  end
336
359
 
@@ -358,7 +381,8 @@ describe Devise::Models::G5Authenticatable do
358
381
  end
359
382
 
360
383
  it 'executes the callback to update role data' do
361
- expect_any_instance_of(model_class).to receive(:update_roles_from_auth).with(auth_data)
384
+ expect_any_instance_of(model_class).to receive(:update_roles_from_auth)
385
+ .with(auth_data)
362
386
  find_and_update
363
387
  end
364
388
  end
@@ -369,7 +393,8 @@ describe Devise::Models::G5Authenticatable do
369
393
  end
370
394
 
371
395
  it 'does not execute the callback to update role data' do
372
- expect_any_instance_of(model_class).to_not receive(:update_roles_from_auth)
396
+ expect_any_instance_of(model_class)
397
+ .to_not receive(:update_roles_from_auth)
373
398
  find_and_update
374
399
  end
375
400
  end
@@ -381,7 +406,8 @@ describe Devise::Models::G5Authenticatable do
381
406
  let(:auth_data) do
382
407
  OmniAuth::AuthHash.new(provider: 'g5',
383
408
  uid: uid,
384
- info: { name: 'Foo Bar', email: 'foo@bar.com' },
409
+ info: { name: 'Foo Bar',
410
+ email: 'foo@bar.com' },
385
411
  credentials: { token: 'abc123' })
386
412
  end
387
413
 
@@ -464,7 +490,8 @@ describe Devise::Models::G5Authenticatable do
464
490
  let(:auth_data) do
465
491
  OmniAuth::AuthHash.new(provider: 'g5',
466
492
  uid: '123999',
467
- info: { name: 'Foo Bar', email: 'foo@bar.com' },
493
+ info: { name: 'Foo Bar',
494
+ email: 'foo@bar.com' },
468
495
  credentials: { token: 'abc123' })
469
496
  end
470
497
 
@@ -475,7 +502,8 @@ describe Devise::Models::G5Authenticatable do
475
502
  end
476
503
 
477
504
  it 'should update the g5_access_token' do
478
- expect { update_g5_credentials }.to change { model.g5_access_token }.to(auth_data.credentials.token)
505
+ expect { update_g5_credentials }.to change { model.g5_access_token }
506
+ .to(auth_data.credentials.token)
479
507
  end
480
508
 
481
509
  it 'should not save the changes' do
@@ -488,7 +516,10 @@ describe Devise::Models::G5Authenticatable do
488
516
  subject(:revoke_g5_credentials!) { model.revoke_g5_credentials! }
489
517
 
490
518
  let(:auth_updater) { double(:auth_user_updater, update: nil) }
491
- before { allow(Devise::G5::AuthUserUpdater).to receive(:new).and_return(auth_updater) }
519
+ before do
520
+ allow(Devise::G5::AuthUserUpdater).to receive(:new)
521
+ .and_return(auth_updater)
522
+ end
492
523
 
493
524
  let(:model) { create(:user, g5_access_token: g5_token) }
494
525
  before { model.password = model.password_confirmation = nil }
@@ -523,11 +554,14 @@ describe Devise::Models::G5Authenticatable do
523
554
  let(:auth_data) do
524
555
  OmniAuth::AuthHash.new(provider: 'g5',
525
556
  uid: '123999',
526
- info: { name: 'Foo Bar', email: 'foo@bar.com' },
557
+ info: { name: 'Foo Bar',
558
+ email: 'foo@bar.com' },
527
559
  credentials: { token: 'abc123' })
528
560
  end
529
561
 
530
- before { allow_any_instance_of(model_class).to receive(:update_roles_from_auth) }
562
+ before do
563
+ allow_any_instance_of(model_class).to receive(:update_roles_from_auth)
564
+ end
531
565
 
532
566
  context 'with params' do
533
567
  let(:params) do
@@ -553,12 +587,13 @@ describe Devise::Models::G5Authenticatable do
553
587
  end
554
588
 
555
589
  it 'executes the callback to update role data' do
556
- expect(new_with_session).to have_received(:update_roles_from_auth).with(auth_data)
590
+ expect(new_with_session).to have_received(:update_roles_from_auth)
591
+ .with(auth_data)
557
592
  end
558
593
  end
559
594
 
560
595
  context 'without session data' do
561
- let(:session) { Hash.new }
596
+ let(:session) { {} }
562
597
 
563
598
  it { is_expected.to be_new_record }
564
599
 
@@ -575,14 +610,15 @@ describe Devise::Models::G5Authenticatable do
575
610
  end
576
611
 
577
612
  it 'should not execute the callback to update role data' do
578
- expect_any_instance_of(model_class).not_to receive(:update_roles_from_auth)
613
+ expect_any_instance_of(model_class)
614
+ .not_to receive(:update_roles_from_auth)
579
615
  new_with_session
580
616
  end
581
617
  end
582
618
  end
583
619
 
584
620
  context 'without params' do
585
- let(:params) { Hash.new }
621
+ let(:params) { {} }
586
622
 
587
623
  context 'with session data' do
588
624
  let(:session) do
@@ -604,12 +640,13 @@ describe Devise::Models::G5Authenticatable do
604
640
  end
605
641
 
606
642
  it 'executes the callback to update role data' do
607
- expect(new_with_session).to have_received(:update_roles_from_auth).with(auth_data)
643
+ expect(new_with_session).to have_received(:update_roles_from_auth)
644
+ .with(auth_data)
608
645
  end
609
646
  end
610
647
 
611
648
  context 'without session data' do
612
- let(:session) { Hash.new }
649
+ let(:session) { {} }
613
650
 
614
651
  it { is_expected.to be_new_record }
615
652
 
@@ -626,7 +663,8 @@ describe Devise::Models::G5Authenticatable do
626
663
  end
627
664
 
628
665
  it 'does not execute the callback to update role data' do
629
- expect_any_instance_of(model_class).not_to receive(:update_roles_from_auth)
666
+ expect_any_instance_of(model_class)
667
+ .not_to receive(:update_roles_from_auth)
630
668
  new_with_session
631
669
  end
632
670
  end
@@ -642,10 +680,10 @@ describe Devise::Models::G5Authenticatable do
642
680
  info: { first_name: 'Foo',
643
681
  last_name: 'Bar',
644
682
  email: 'foo@bar.com',
645
- phone: '123-555-1212 x42'},
683
+ phone: '123-555-1212 x42' },
646
684
  credentials: { token: 'abc123' },
647
685
  extra: { title: 'Minister of Funny Walks',
648
- organization_name: 'Dept of Redundancy Dept' })
686
+ organization_name: 'Sales' })
649
687
  end
650
688
 
651
689
  it 'has the correct uid' do
@@ -668,8 +706,10 @@ describe Devise::Models::G5Authenticatable do
668
706
  OmniAuth::AuthHash.new(provider: 'g5',
669
707
  uid: '123456',
670
708
  extra: { roles: [
671
- { name: 'Admin', type: 'GLOBAL', urn: nil }
672
- ]})
709
+ { name: 'Admin',
710
+ type: 'GLOBAL',
711
+ urn: nil }
712
+ ] })
673
713
  end
674
714
 
675
715
  it 'does not change anything on the model' do
@@ -1,25 +1,30 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe DeviseG5Authenticatable::Models::ProtectedAttributes do
4
- before do
5
- Dummy::Application.config.active_record.whitelist_attributes = true
6
- end
3
+ require 'rails_helper'
7
4
 
8
- after do
9
- Dummy::Application.config.active_record.whitelist_attributes = false
10
- end
5
+ # Protected attributes are not supported by rails 5
6
+ if Rails.version.starts_with?('4')
7
+ RSpec.describe DeviseG5Authenticatable::Models::ProtectedAttributes do
8
+ before do
9
+ Dummy::Application.config.active_record.whitelist_attributes = true
10
+ end
11
11
 
12
- subject { model }
12
+ after do
13
+ Dummy::Application.config.active_record.whitelist_attributes = false
14
+ end
13
15
 
14
- let(:model_class) { User }
15
- let(:model) { model_class.new }
16
+ subject { model }
16
17
 
17
- it { should allow_mass_assignment_of(:email) }
18
- it { should allow_mass_assignment_of(:password) }
19
- it { should allow_mass_assignment_of(:password_confirmation) }
20
- it { should allow_mass_assignment_of(:provider) }
21
- it { should allow_mass_assignment_of(:uid) }
22
- it { should_not allow_mass_assignment_of(:g5_access_token) }
23
- it { should allow_mass_assignment_of(:current_password) }
24
- it { should allow_mass_assignment_of(:updated_by) }
18
+ let(:model_class) { User }
19
+ let(:model) { model_class.new }
20
+
21
+ it { is_expected.to allow_mass_assignment_of(:email) }
22
+ it { is_expected.to allow_mass_assignment_of(:password) }
23
+ it { is_expected.to allow_mass_assignment_of(:password_confirmation) }
24
+ it { is_expected.to allow_mass_assignment_of(:provider) }
25
+ it { is_expected.to allow_mass_assignment_of(:uid) }
26
+ it { is_expected.not_to allow_mass_assignment_of(:g5_access_token) }
27
+ it { is_expected.to allow_mass_assignment_of(:current_password) }
28
+ it { is_expected.to allow_mass_assignment_of(:updated_by) }
29
+ end
25
30
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # Load rails dummy application
6
+ ENV['RAILS_ENV'] = 'test'
7
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
8
+
9
+ require 'rspec/rails'
10
+ require 'capybara/rspec'
11
+ require 'webmock/rspec'
12
+ require 'shoulda-matchers'
13
+ require 'factory_girl_rails'
14
+
15
+ # Load support files
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
17
+
18
+ # Checks for pending migration and applies them before tests are run
19
+ ActiveRecord::Migration.maintain_test_schema!
20
+
21
+ RSpec.configure do |config|
22
+ config.include FactoryGirl::Syntax::Methods
23
+
24
+ config.use_transactional_fixtures = true
25
+
26
+ config.infer_spec_type_from_file_location!
27
+
28
+ # The integration tests can be run with:
29
+ # rspec -t type:feature
30
+ # config.filter_run_excluding type: 'feature'
31
+
32
+ # Filter lines from Rails gems in backtraces
33
+ # config.filter_rails_from_backtrace!
34
+
35
+ # arbitrary gems may also be filtered via:
36
+ # config.filter_gems_from_backtrace('gem name')
37
+
38
+ config.after(:suite) { WebMock.disable! }
39
+ end
40
+
41
+ Shoulda::Matchers.configure do |config|
42
+ config.integrate do |with|
43
+ with.test_framework :rspec
44
+ with.library :rails
45
+ end
46
+ end