devise_g5_authenticatable 0.3.0 → 1.0.0.pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +29 -7
- data/Appraisals +21 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +11 -7
- data/README.md +6 -6
- data/Rakefile +6 -5
- data/app/controllers/devise_g5_authenticatable/registrations_controller.rb +3 -0
- data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +9 -5
- data/config/initializers/devise_g5_authenticatable.rb +2 -0
- data/devise_g5_authenticatable.gemspec +6 -5
- data/gemfiles/rails_4.1.gemfile +26 -0
- data/gemfiles/rails_4.2.gemfile +26 -0
- data/gemfiles/rails_5.0.gemfile +26 -0
- data/gemfiles/rails_5.1.gemfile +26 -0
- data/lib/devise_g5_authenticatable/controllers/helpers.rb +5 -0
- data/lib/devise_g5_authenticatable/controllers/url_helpers.rb +3 -0
- data/lib/devise_g5_authenticatable/engine.rb +4 -1
- data/lib/devise_g5_authenticatable/g5/auth_password_validator.rb +6 -1
- data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +16 -15
- data/lib/devise_g5_authenticatable/g5/auth_user_updater.rb +11 -5
- data/lib/devise_g5_authenticatable/g5/user_exporter.rb +11 -6
- data/lib/devise_g5_authenticatable/g5.rb +2 -0
- data/lib/devise_g5_authenticatable/hooks/g5_authenticatable.rb +8 -3
- data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +38 -26
- data/lib/devise_g5_authenticatable/models/protected_attributes.rb +11 -2
- data/lib/devise_g5_authenticatable/omniauth.rb +8 -2
- data/lib/devise_g5_authenticatable/routes.rb +48 -35
- data/lib/devise_g5_authenticatable/version.rb +3 -1
- data/lib/devise_g5_authenticatable.rb +4 -1
- data/spec/controllers/helpers_spec.rb +54 -49
- data/spec/controllers/sessions_controller_spec.rb +67 -39
- data/spec/controllers/url_helpers_spec.rb +78 -78
- data/spec/dummy/app/views/{anonymous → devise}/new.html.erb +0 -0
- data/spec/dummy/config/environments/test.rb +20 -4
- data/spec/dummy/config/initializers/devise.rb +5 -1
- data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
- data/spec/dummy/db/migrate/20131230235849_devise_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20140102213131_drop_database_authenticatable.rb +3 -1
- data/spec/dummy/db/migrate/20140103032308_drop_recoverable.rb +3 -1
- data/spec/dummy/db/migrate/20140103042329_drop_rememberable.rb +3 -1
- data/spec/dummy/db/migrate/20140103174810_add_omniauth_columns_to_users.rb +3 -1
- data/spec/dummy/db/migrate/20140103191601_add_email_back_to_user.rb +3 -1
- data/spec/dummy/db/migrate/20140113202948_devise_create_admins.rb +3 -1
- data/spec/dummy/db/migrate/20140113233821_add_provider_and_uid_to_admins.rb +3 -1
- data/spec/dummy/db/schema.rb +29 -29
- data/spec/factories/admin.rb +2 -0
- data/spec/factories/user.rb +2 -0
- data/spec/features/edit_registration_spec.rb +22 -13
- data/spec/features/registration_spec.rb +13 -8
- data/spec/features/sign_in_spec.rb +4 -2
- data/spec/features/sign_out_spec.rb +4 -2
- data/spec/features/token_validation_spec.rb +24 -14
- data/spec/g5/auth_password_validator_spec.rb +28 -15
- data/spec/g5/auth_user_creator_spec.rb +29 -22
- data/spec/g5/auth_user_updater_spec.rb +23 -16
- data/spec/g5/user_exporter_spec.rb +36 -31
- data/spec/models/g5_authenticatable_spec.rb +78 -38
- data/spec/models/protected_attributes_spec.rb +24 -19
- data/spec/rails_helper.rb +46 -0
- data/spec/routing/registrations_routing_spec.rb +43 -27
- data/spec/routing/sessions_routing_spec.rb +46 -29
- data/spec/spec_helper.rb +93 -27
- data/spec/support/controller_test_helpers.rb +15 -0
- data/spec/support/devise.rb +9 -1
- data/spec/support/shared_contexts/custom_router.rb +16 -0
- data/spec/support/shared_contexts/oauth_error.rb +4 -2
- data/spec/support/shared_contexts/rake.rb +10 -4
- data/spec/support/shared_examples/registration_error.rb +3 -1
- data/spec/support/{user_feature_methods.rb → user_omniauth_methods.rb} +9 -5
- data/spec/tasks/export_users_spec.rb +5 -3
- metadata +30 -26
- data/circle.yml +0 -4
- data/spec/support/omniauth.rb +0 -3
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe DeviseG5Authenticatable::SessionsController do
|
4
6
|
before { request.env['devise.mapping'] = Devise.mappings[scope] }
|
5
7
|
let(:scope) { :user }
|
6
8
|
|
7
9
|
describe '#new' do
|
8
|
-
subject(:new_session) { get
|
10
|
+
subject(:new_session) { get(:new) }
|
9
11
|
|
10
12
|
context 'with user scope' do
|
11
13
|
it 'should redirect to the scoped authorize path' do
|
@@ -23,7 +25,7 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
23
25
|
end
|
24
26
|
|
25
27
|
describe '#omniauth_passthru' do
|
26
|
-
subject(:passthru) { get
|
28
|
+
subject(:passthru) { get(:omniauth_passthru) }
|
27
29
|
|
28
30
|
it 'should return a 404' do
|
29
31
|
expect(passthru).to be_not_found
|
@@ -31,38 +33,43 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
describe '#create' do
|
34
|
-
subject(:create_session) { post
|
36
|
+
subject(:create_session) { post(:create) }
|
35
37
|
|
36
38
|
let(:auth_hash) do
|
37
|
-
OmniAuth::AuthHash.new(
|
39
|
+
OmniAuth::AuthHash.new(
|
38
40
|
provider: 'g5',
|
39
41
|
uid: '45',
|
40
|
-
info: {name: 'Foo Bar',
|
41
|
-
|
42
|
-
credentials: {token: 'abc123'}
|
43
|
-
|
42
|
+
info: { name: 'Foo Bar',
|
43
|
+
email: 'foo@bar.com' },
|
44
|
+
credentials: { token: 'abc123' }
|
45
|
+
)
|
44
46
|
end
|
45
47
|
before { request.env['omniauth.auth'] = auth_hash }
|
46
48
|
|
47
49
|
context 'when local model exists' do
|
48
50
|
let(:model) do
|
49
|
-
stub_model(model_class,
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
stub_model(model_class,
|
52
|
+
provider: auth_hash.provider,
|
53
|
+
uid: auth_hash.uid,
|
54
|
+
email: auth_hash.email,
|
55
|
+
g5_access_token: auth_hash.credentials.token,
|
56
|
+
save!: true,
|
57
|
+
update_g5_credentials: true,
|
58
|
+
email_changed?: false)
|
59
|
+
end
|
60
|
+
before do
|
61
|
+
allow(model_class).to receive(:find_and_update_for_g5_oauth)
|
62
|
+
.and_return(model)
|
56
63
|
end
|
57
|
-
before { model_class.stub(find_and_update_for_g5_oauth: model) }
|
58
64
|
|
59
65
|
context 'with user scope' do
|
60
66
|
let(:model_class) { User }
|
61
67
|
let(:scope) { :user }
|
62
68
|
|
63
69
|
it 'should find the user and update the oauth credentials' do
|
64
|
-
User.should_receive(:find_and_update_for_g5_oauth).with(auth_hash).and_return(model)
|
65
70
|
create_session
|
71
|
+
expect(User).to have_received(:find_and_update_for_g5_oauth)
|
72
|
+
.with(auth_hash)
|
66
73
|
end
|
67
74
|
|
68
75
|
it 'should set the flash message' do
|
@@ -71,7 +78,8 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
71
78
|
end
|
72
79
|
|
73
80
|
it 'should sign in the user' do
|
74
|
-
expect { create_session }.to change { controller.current_user }
|
81
|
+
expect { create_session }.to change { controller.current_user }
|
82
|
+
.from(nil).to(model)
|
75
83
|
end
|
76
84
|
|
77
85
|
it 'should redirect the user' do
|
@@ -85,18 +93,23 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
85
93
|
let(:scope) { :admin }
|
86
94
|
|
87
95
|
it 'should find the admin and update the oauth credentials' do
|
88
|
-
Admin.should_receive(:find_and_update_for_g5_oauth).with(auth_hash).and_return(model)
|
89
96
|
create_session
|
97
|
+
expect(Admin).to have_received(:find_and_update_for_g5_oauth)
|
98
|
+
.with(auth_hash)
|
90
99
|
end
|
91
100
|
|
92
101
|
it 'should sign in the admin' do
|
93
|
-
expect { create_session }.to change { controller.current_admin }
|
102
|
+
expect { create_session }.to change { controller.current_admin }
|
103
|
+
.from(nil).to(model)
|
94
104
|
end
|
95
105
|
end
|
96
106
|
end
|
97
107
|
|
98
108
|
context 'when local model does not exist' do
|
99
|
-
before
|
109
|
+
before do
|
110
|
+
allow(model_class).to receive(:find_and_update_for_g5_oauth)
|
111
|
+
.and_return(nil)
|
112
|
+
end
|
100
113
|
|
101
114
|
context 'with user scope' do
|
102
115
|
let(:scope) { :user }
|
@@ -116,7 +129,8 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
116
129
|
end
|
117
130
|
|
118
131
|
it 'should set the auth data on the session' do
|
119
|
-
expect { create_session }.to change { session['omniauth.auth'] }
|
132
|
+
expect { create_session }.to change { session['omniauth.auth'] }
|
133
|
+
.to(auth_hash)
|
120
134
|
end
|
121
135
|
end
|
122
136
|
|
@@ -129,19 +143,23 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
129
143
|
end
|
130
144
|
|
131
145
|
it 'should set the auth data on the session' do
|
132
|
-
expect { create_session }.to change { session['omniauth.auth'] }
|
146
|
+
expect { create_session }.to change { session['omniauth.auth'] }
|
147
|
+
.to(auth_hash)
|
133
148
|
end
|
134
149
|
end
|
135
150
|
end
|
136
151
|
end
|
137
152
|
|
138
153
|
describe '#destroy' do
|
139
|
-
subject(:destroy_session) { delete
|
154
|
+
subject(:destroy_session) { delete(:destroy) }
|
140
155
|
|
141
156
|
let(:auth_client) { double(:auth_client, sign_out_url: auth_sign_out_url) }
|
142
|
-
let(:auth_sign_out_url)
|
157
|
+
let(:auth_sign_out_url) do
|
158
|
+
'https://auth.test.host/sign_out?redirect_url=http%3A%2F%2Ftest.host%2F'
|
159
|
+
end
|
143
160
|
before do
|
144
|
-
allow(G5AuthenticationClient::Client).to receive(:new)
|
161
|
+
allow(G5AuthenticationClient::Client).to receive(:new)
|
162
|
+
.and_return(auth_client)
|
145
163
|
end
|
146
164
|
|
147
165
|
let(:model) { create(scope) }
|
@@ -151,16 +169,17 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
151
169
|
let(:scope) { :user }
|
152
170
|
|
153
171
|
context 'when there is a current user' do
|
154
|
-
before { sign_in(
|
172
|
+
before { sign_in(model, scope: scope) }
|
155
173
|
|
156
174
|
it 'should sign out the user locally' do
|
157
|
-
expect { destroy_session }.to change { controller.current_user }
|
175
|
+
expect { destroy_session }.to change { controller.current_user }
|
176
|
+
.to(nil)
|
158
177
|
end
|
159
178
|
|
160
179
|
it 'should construct the sign out URL with the correct redirect URL' do
|
161
|
-
expect(auth_client).to receive(:sign_out_url)
|
162
|
-
with(root_url)
|
163
|
-
and_return(auth_sign_out_url)
|
180
|
+
expect(auth_client).to receive(:sign_out_url)
|
181
|
+
.with(root_url)
|
182
|
+
.and_return(auth_sign_out_url)
|
164
183
|
destroy_session
|
165
184
|
end
|
166
185
|
|
@@ -184,10 +203,11 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
184
203
|
context 'with admin scope' do
|
185
204
|
let(:scope) { :admin }
|
186
205
|
|
187
|
-
before { sign_in(
|
206
|
+
before { sign_in(model, scope: scope) }
|
188
207
|
|
189
208
|
it 'should sign out the admin locally' do
|
190
|
-
expect { destroy_session }.to change { controller.current_admin }
|
209
|
+
expect { destroy_session }.to change { controller.current_admin }
|
210
|
+
.to(nil)
|
191
211
|
end
|
192
212
|
|
193
213
|
it 'should revoke the g5 access token' do
|
@@ -202,7 +222,9 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
202
222
|
# We need some trickery here because the failure action is actually rack
|
203
223
|
# rather than rails
|
204
224
|
rack_response = described_class.action(:failure).call(request.env)
|
205
|
-
@response = ActionDispatch::TestResponse.
|
225
|
+
@response = ActionDispatch::TestResponse.new(rack_response[0],
|
226
|
+
rack_response[1],
|
227
|
+
rack_response[2].body)
|
206
228
|
end
|
207
229
|
|
208
230
|
before do
|
@@ -218,7 +240,9 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
218
240
|
|
219
241
|
it 'should set the flash message' do
|
220
242
|
failure
|
221
|
-
expect(flash[:alert]).to eq(
|
243
|
+
expect(flash[:alert]).to eq(
|
244
|
+
"Could not authenticate you from G5 because \"#{reason}\"."
|
245
|
+
)
|
222
246
|
end
|
223
247
|
|
224
248
|
it 'should be a redirect' do
|
@@ -238,7 +262,9 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
238
262
|
|
239
263
|
it 'should set the flash message' do
|
240
264
|
failure
|
241
|
-
expect(flash[:alert]).to eq(
|
265
|
+
expect(flash[:alert]).to eq(
|
266
|
+
"Could not authenticate you from G5 because \"#{message}\"."
|
267
|
+
)
|
242
268
|
end
|
243
269
|
|
244
270
|
it 'should redirect to the root path' do
|
@@ -253,7 +279,9 @@ describe DeviseG5Authenticatable::SessionsController do
|
|
253
279
|
|
254
280
|
it 'should set the flash message' do
|
255
281
|
failure
|
256
|
-
expect(flash[:alert]).to eq(
|
282
|
+
expect(flash[:alert]).to eq(
|
283
|
+
"Could not authenticate you from G5 because \"#{humanized_type}\"."
|
284
|
+
)
|
257
285
|
end
|
258
286
|
|
259
287
|
it 'should redirect to the root path' do
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe DeviseG5Authenticatable::UrlHelpers do
|
4
6
|
controller(ActionController::Base) do
|
5
7
|
include DeviseG5Authenticatable::UrlHelpers
|
6
8
|
end
|
@@ -12,60 +14,59 @@ describe DeviseG5Authenticatable::UrlHelpers do
|
|
12
14
|
context 'with user resource' do
|
13
15
|
let(:resource_or_scope) { build_stubbed(:user) }
|
14
16
|
|
15
|
-
it {
|
17
|
+
it { is_expected.to eq(user_g5_authorize_path) }
|
16
18
|
end
|
17
19
|
|
18
20
|
context 'with admin resource' do
|
19
21
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
20
22
|
|
21
|
-
it {
|
23
|
+
it { is_expected.to eq(admin_g5_authorize_path) }
|
22
24
|
end
|
23
25
|
|
24
26
|
context 'with user scope' do
|
25
27
|
let(:resource_or_scope) { :user }
|
26
28
|
|
27
|
-
it {
|
29
|
+
it { is_expected.to eq(user_g5_authorize_path) }
|
28
30
|
end
|
29
31
|
|
30
32
|
context 'with admin scope' do
|
31
33
|
let(:resource_or_scope) { :admin }
|
32
34
|
|
33
|
-
it {
|
35
|
+
it { is_expected.to eq(admin_g5_authorize_path) }
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
39
|
context 'with custom router' do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
include_context 'custom router'
|
41
|
+
before do
|
42
|
+
allow(custom_router).to receive(:user_g5_authorize_path)
|
43
|
+
.and_return('foo')
|
44
|
+
allow(custom_router).to receive(:admin_g5_authorize_path)
|
45
|
+
.and_return('bar')
|
44
46
|
end
|
45
|
-
before { controller.stub(my_engine: custom_router) }
|
46
47
|
|
47
48
|
context 'with user resource' do
|
48
49
|
let(:resource_or_scope) { build_stubbed(:user) }
|
49
50
|
|
50
|
-
it {
|
51
|
+
it { is_expected.to eq(custom_router.user_g5_authorize_path) }
|
51
52
|
end
|
52
53
|
|
53
54
|
context 'with admin resource' do
|
54
55
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
55
56
|
|
56
|
-
it {
|
57
|
+
it { is_expected.to eq(custom_router.admin_g5_authorize_path) }
|
57
58
|
end
|
58
59
|
|
59
60
|
context 'with user scope' do
|
60
61
|
let(:resource_or_scope) { :user }
|
61
62
|
|
62
|
-
it {
|
63
|
+
it { is_expected.to eq(custom_router.user_g5_authorize_path) }
|
63
64
|
end
|
64
65
|
|
65
66
|
context 'with admin scope' do
|
66
67
|
let(:resource_or_scope) { :admin }
|
67
68
|
|
68
|
-
it {
|
69
|
+
it { is_expected.to eq(custom_router.admin_g5_authorize_path) }
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
@@ -77,190 +78,191 @@ describe DeviseG5Authenticatable::UrlHelpers do
|
|
77
78
|
context 'with user resource' do
|
78
79
|
let(:resource_or_scope) { build_stubbed(:user) }
|
79
80
|
|
80
|
-
it {
|
81
|
+
it { is_expected.to eq(user_g5_callback_path) }
|
81
82
|
end
|
82
83
|
|
83
84
|
context 'with admin resource' do
|
84
85
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
85
86
|
|
86
|
-
it {
|
87
|
+
it { is_expected.to eq(admin_g5_callback_path) }
|
87
88
|
end
|
88
89
|
|
89
90
|
context 'with user scope' do
|
90
91
|
let(:resource_or_scope) { :user }
|
91
92
|
|
92
|
-
it {
|
93
|
+
it { is_expected.to eq(user_g5_callback_path) }
|
93
94
|
end
|
94
95
|
|
95
96
|
context 'with admin scope' do
|
96
97
|
let(:resource_or_scope) { :admin }
|
97
98
|
|
98
|
-
it {
|
99
|
+
it { is_expected.to eq(admin_g5_callback_path) }
|
99
100
|
end
|
100
101
|
end
|
101
102
|
|
102
103
|
context 'with custom router' do
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
include_context 'custom router'
|
105
|
+
before do
|
106
|
+
allow(custom_router).to receive(:user_g5_callback_path)
|
107
|
+
.and_return('foo_callback')
|
108
|
+
allow(custom_router).to receive(:admin_g5_callback_path)
|
109
|
+
.and_return('bar_callback')
|
109
110
|
end
|
110
|
-
before { controller.stub(my_engine: custom_router) }
|
111
111
|
|
112
112
|
context 'with user resource' do
|
113
113
|
let(:resource_or_scope) { build_stubbed(:user) }
|
114
114
|
|
115
|
-
it {
|
115
|
+
it { is_expected.to eq(custom_router.user_g5_callback_path) }
|
116
116
|
end
|
117
117
|
|
118
118
|
context 'with admin resource' do
|
119
119
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
120
120
|
|
121
|
-
it {
|
121
|
+
it { is_expected.to eq(custom_router.admin_g5_callback_path) }
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'with user scope' do
|
125
125
|
let(:resource_or_scope) { :user }
|
126
126
|
|
127
|
-
it {
|
127
|
+
it { is_expected.to eq(custom_router.user_g5_callback_path) }
|
128
128
|
end
|
129
129
|
|
130
130
|
context 'with admin scope' do
|
131
131
|
let(:resource_or_scope) { :admin }
|
132
132
|
|
133
|
-
it {
|
133
|
+
it { is_expected.to eq(custom_router.admin_g5_callback_path) }
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
138
|
describe '#new_session_path' do
|
139
|
-
subject(:new_session_path)
|
139
|
+
subject(:new_session_path) do
|
140
|
+
controller.new_session_path(resource_or_scope)
|
141
|
+
end
|
140
142
|
|
141
143
|
context 'with main_app router' do
|
142
144
|
context 'with user resource' do
|
143
145
|
let(:resource_or_scope) { build_stubbed(:user) }
|
144
146
|
|
145
|
-
it {
|
147
|
+
it { is_expected.to eq(new_user_session_path) }
|
146
148
|
end
|
147
149
|
|
148
150
|
context 'with admin resource' do
|
149
151
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
150
152
|
|
151
|
-
it {
|
153
|
+
it { is_expected.to eq(new_admin_session_path) }
|
152
154
|
end
|
153
155
|
|
154
156
|
context 'with user scope' do
|
155
157
|
let(:resource_or_scope) { :user }
|
156
158
|
|
157
|
-
it {
|
159
|
+
it { is_expected.to eq(new_user_session_path) }
|
158
160
|
end
|
159
161
|
|
160
162
|
context 'with admin scope' do
|
161
163
|
let(:resource_or_scope) { :admin }
|
162
164
|
|
163
|
-
it {
|
165
|
+
it { is_expected.to eq(new_admin_session_path) }
|
164
166
|
end
|
165
167
|
end
|
166
168
|
|
167
169
|
context 'with custom router' do
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
include_context 'custom router'
|
171
|
+
before do
|
172
|
+
allow(custom_router).to receive(:new_user_session_path)
|
173
|
+
.and_return('foo')
|
174
|
+
allow(custom_router).to receive(:new_admin_session_path)
|
175
|
+
.and_return('bar')
|
174
176
|
end
|
175
|
-
before { controller.stub(my_engine: custom_router) }
|
176
177
|
|
177
178
|
context 'with user resource' do
|
178
179
|
let(:resource_or_scope) { build_stubbed(:user) }
|
179
180
|
|
180
|
-
it {
|
181
|
+
it { is_expected.to eq(custom_router.new_user_session_path) }
|
181
182
|
end
|
182
183
|
|
183
184
|
context 'with admin resource' do
|
184
185
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
185
186
|
|
186
|
-
it {
|
187
|
+
it { is_expected.to eq(custom_router.new_admin_session_path) }
|
187
188
|
end
|
188
189
|
|
189
190
|
context 'with user scope' do
|
190
191
|
let(:resource_or_scope) { :user }
|
191
192
|
|
192
|
-
it {
|
193
|
+
it { is_expected.to eq(custom_router.new_user_session_path) }
|
193
194
|
end
|
194
195
|
|
195
196
|
context 'with admin scope' do
|
196
197
|
let(:resource_or_scope) { :admin }
|
197
198
|
|
198
|
-
it {
|
199
|
+
it { is_expected.to eq(custom_router.new_admin_session_path) }
|
199
200
|
end
|
200
201
|
end
|
201
202
|
end
|
202
203
|
|
203
204
|
describe '#destroy_session_path' do
|
204
|
-
subject(:destroy_session_path)
|
205
|
+
subject(:destroy_session_path) do
|
206
|
+
controller.destroy_session_path(resource_or_scope)
|
207
|
+
end
|
205
208
|
|
206
209
|
context 'with main_app router' do
|
207
210
|
context 'with user resource' do
|
208
211
|
let(:resource_or_scope) { build_stubbed(:user) }
|
209
212
|
|
210
|
-
it {
|
213
|
+
it { is_expected.to eq(destroy_user_session_path) }
|
211
214
|
end
|
212
215
|
|
213
216
|
context 'with admin resource' do
|
214
217
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
215
218
|
|
216
|
-
it {
|
219
|
+
it { is_expected.to eq(destroy_admin_session_path) }
|
217
220
|
end
|
218
221
|
|
219
222
|
context 'with user scope' do
|
220
223
|
let(:resource_or_scope) { :user }
|
221
224
|
|
222
|
-
it {
|
225
|
+
it { is_expected.to eq(destroy_user_session_path) }
|
223
226
|
end
|
224
227
|
|
225
228
|
context 'with admin scope' do
|
226
229
|
let(:resource_or_scope) { :admin }
|
227
230
|
|
228
|
-
it {
|
231
|
+
it { is_expected.to eq(destroy_admin_session_path) }
|
229
232
|
end
|
230
233
|
end
|
231
234
|
|
232
235
|
context 'with custom router' do
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
236
|
+
include_context 'custom router'
|
237
|
+
before do
|
238
|
+
allow(custom_router).to receive(:destroy_user_session_path)
|
239
|
+
.and_return('foo')
|
240
|
+
allow(custom_router).to receive(:destroy_admin_session_path)
|
241
|
+
.and_return('bar')
|
239
242
|
end
|
240
|
-
before { controller.stub(my_engine: custom_router) }
|
241
243
|
|
242
244
|
context 'with user resource' do
|
243
245
|
let(:resource_or_scope) { build_stubbed(:user) }
|
244
246
|
|
245
|
-
it {
|
247
|
+
it { is_expected.to eq(custom_router.destroy_user_session_path) }
|
246
248
|
end
|
247
249
|
|
248
250
|
context 'with admin resource' do
|
249
251
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
250
252
|
|
251
|
-
it {
|
253
|
+
it { is_expected.to eq(custom_router.destroy_admin_session_path) }
|
252
254
|
end
|
253
255
|
|
254
256
|
context 'with user scope' do
|
255
257
|
let(:resource_or_scope) { :user }
|
256
258
|
|
257
|
-
it {
|
259
|
+
it { is_expected.to eq(custom_router.destroy_user_session_path) }
|
258
260
|
end
|
259
261
|
|
260
262
|
context 'with admin scope' do
|
261
263
|
let(:resource_or_scope) { :admin }
|
262
264
|
|
263
|
-
it {
|
265
|
+
it { is_expected.to eq(custom_router.destroy_admin_session_path) }
|
264
266
|
end
|
265
267
|
end
|
266
268
|
end
|
@@ -272,60 +274,58 @@ describe DeviseG5Authenticatable::UrlHelpers do
|
|
272
274
|
context 'with user resource' do
|
273
275
|
let(:resource_or_scope) { build_stubbed(:user) }
|
274
276
|
|
275
|
-
it {
|
277
|
+
it { is_expected.to eq(user_session_path) }
|
276
278
|
end
|
277
279
|
|
278
280
|
context 'with admin resource' do
|
279
281
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
280
282
|
|
281
|
-
it {
|
283
|
+
it { is_expected.to eq(admin_session_path) }
|
282
284
|
end
|
283
285
|
|
284
286
|
context 'with user scope' do
|
285
287
|
let(:resource_or_scope) { :user }
|
286
288
|
|
287
|
-
it {
|
289
|
+
it { is_expected.to eq(user_session_path) }
|
288
290
|
end
|
289
291
|
|
290
292
|
context 'with admin scope' do
|
291
293
|
let(:resource_or_scope) { :admin }
|
292
294
|
|
293
|
-
it {
|
295
|
+
it { is_expected.to eq(admin_session_path) }
|
294
296
|
end
|
295
297
|
end
|
296
298
|
|
297
299
|
context 'with custom router' do
|
298
|
-
|
299
|
-
after { Devise.router_name = nil }
|
300
|
+
include_context 'custom router'
|
300
301
|
|
301
|
-
|
302
|
-
|
303
|
-
|
302
|
+
before do
|
303
|
+
allow(custom_router).to receive(:user_session_path).and_return('foo')
|
304
|
+
allow(custom_router).to receive(:admin_session_path).and_return('bar')
|
304
305
|
end
|
305
|
-
before { controller.stub(my_engine: custom_router) }
|
306
306
|
|
307
307
|
context 'with user resource' do
|
308
308
|
let(:resource_or_scope) { build_stubbed(:user) }
|
309
309
|
|
310
|
-
it {
|
310
|
+
it { is_expected.to eq(custom_router.user_session_path) }
|
311
311
|
end
|
312
312
|
|
313
313
|
context 'with admin resource' do
|
314
314
|
let(:resource_or_scope) { build_stubbed(:admin) }
|
315
315
|
|
316
|
-
it {
|
316
|
+
it { is_expected.to eq(custom_router.admin_session_path) }
|
317
317
|
end
|
318
318
|
|
319
319
|
context 'with user scope' do
|
320
320
|
let(:resource_or_scope) { :user }
|
321
321
|
|
322
|
-
it {
|
322
|
+
it { is_expected.to eq(custom_router.user_session_path) }
|
323
323
|
end
|
324
324
|
|
325
325
|
context 'with admin scope' do
|
326
326
|
let(:resource_or_scope) { :admin }
|
327
327
|
|
328
|
-
it {
|
328
|
+
it { is_expected.to eq(custom_router.admin_session_path) }
|
329
329
|
end
|
330
330
|
end
|
331
331
|
end
|
File without changes
|
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Dummy::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in
|
4
|
+
# Settings specified here will take precedence over those in
|
5
|
+
# config/application.rb
|
3
6
|
|
4
7
|
# The test environment is used exclusively to run your application's
|
5
8
|
# test suite. You never need to work with it otherwise. Remember that
|
@@ -8,8 +11,21 @@ Dummy::Application.configure do
|
|
8
11
|
config.cache_classes = true
|
9
12
|
|
10
13
|
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
|
12
|
-
config.
|
14
|
+
cache_header_value = 'public, max-age=3600'
|
15
|
+
if config.respond_to?(:public_file_server=)
|
16
|
+
config.public_file_server.enabled = true
|
17
|
+
config.public_file_server.headers = {
|
18
|
+
'Cache-Control' => cache_header_value
|
19
|
+
}
|
20
|
+
else
|
21
|
+
config.static_cache_controller = cache_header_value
|
22
|
+
|
23
|
+
if config.respond_to?(:serve_static_files=)
|
24
|
+
config.serve_static_files = true
|
25
|
+
else
|
26
|
+
config.serve_static_assets = true
|
27
|
+
end
|
28
|
+
end
|
13
29
|
|
14
30
|
# Show full error reports and disable caching
|
15
31
|
config.consider_all_requests_local = true
|
@@ -19,7 +35,7 @@ Dummy::Application.configure do
|
|
19
35
|
config.action_dispatch.show_exceptions = false
|
20
36
|
|
21
37
|
# Disable request forgery protection in test environment
|
22
|
-
config.action_controller.allow_forgery_protection
|
38
|
+
config.action_controller.allow_forgery_protection = false
|
23
39
|
|
24
40
|
# Tell Action Mailer not to deliver emails to the real world.
|
25
41
|
# The :test delivery method accumulates sent emails in the
|