switch_user 1.5.0 → 1.5.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/CHANGELOG.md +5 -0
- data/Gemfile +2 -0
- data/README.md +1 -0
- data/Rakefile +2 -0
- data/app/controllers/switch_user_controller.rb +6 -4
- data/app/helpers/switch_user_helper.rb +8 -8
- data/config/routes.rb +2 -0
- data/lib/generators/switch_user/install/install_generator.rb +2 -1
- data/lib/generators/switch_user/install/templates/switch_user.rb +5 -3
- data/lib/switch_user.rb +12 -12
- data/lib/switch_user/base_guard.rb +4 -2
- data/lib/switch_user/data_source.rb +6 -6
- data/lib/switch_user/lambda_guard.rb +2 -0
- data/lib/switch_user/provider.rb +15 -13
- data/lib/switch_user/provider/authlogic.rb +6 -6
- data/lib/switch_user/provider/base.rb +5 -4
- data/lib/switch_user/provider/clearance.rb +5 -3
- data/lib/switch_user/provider/devise.rb +2 -0
- data/lib/switch_user/provider/dummy.rb +8 -12
- data/lib/switch_user/provider/restful_authentication.rb +5 -3
- data/lib/switch_user/provider/session.rb +5 -3
- data/lib/switch_user/provider/sorcery.rb +6 -6
- data/lib/switch_user/rails.rb +3 -1
- data/lib/switch_user/rspec.rb +2 -2
- data/lib/switch_user/rspec/feature_helpers.rb +6 -7
- data/lib/switch_user/user_loader.rb +5 -2
- data/lib/switch_user/user_set.rb +5 -3
- data/lib/switch_user/version.rb +3 -1
- data/spec/controllers/switch_user_controller_spec.rb +21 -18
- data/spec/helpers/switch_user_helper_spec.rb +45 -46
- data/spec/integration/switch_user_spec.rb +91 -30
- data/spec/provider/authlogic_spec.rb +3 -1
- data/spec/provider/clearance_spec.rb +3 -1
- data/spec/provider/devise_spec.rb +17 -17
- data/spec/provider/dummy_spec.rb +3 -1
- data/spec/provider/restful_authentication_spec.rb +3 -1
- data/spec/provider/session_spec.rb +3 -1
- data/spec/provider/sorcery_spec.rb +3 -1
- data/spec/provider_spec.rb +3 -1
- data/spec/rspec/feature_helpers_spec.rb +31 -30
- data/spec/spec_helper.rb +3 -1
- data/spec/support/application.rb +13 -12
- data/spec/support/provider.rb +11 -9
- data/spec/switch_user/data_source_spec.rb +3 -1
- data/spec/switch_user/lambda_guard_spec.rb +4 -2
- data/spec/switch_user/user_loader_spec.rb +18 -16
- data/spec/switch_user/user_set_spec.rb +9 -7
- data/spec/switch_user_spec.rb +6 -4
- data/switch_user.gemspec +24 -23
- metadata +19 -19
@@ -1,82 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
RSpec.describe
|
4
|
-
let(:user) { User.create!(email:
|
5
|
-
let(:other_user) { User.create!(email:
|
5
|
+
RSpec.describe 'Using SwitchUser', type: :request do
|
6
|
+
let(:user) { User.create!(email: 'foo@bar.com', admin: true) }
|
7
|
+
let(:other_user) { User.create!(email: 'other@bar.com', admin: false) }
|
6
8
|
|
7
9
|
before do
|
8
10
|
SwitchUser.reset_config
|
9
11
|
SwitchUser.provider = :session
|
10
|
-
SwitchUser.controller_guard = ->(
|
11
|
-
SwitchUser.redirect_path = ->(_, _) {
|
12
|
+
SwitchUser.controller_guard = ->(_current_user, _request) { Rails.env.test? }
|
13
|
+
SwitchUser.redirect_path = ->(_, _) { '/dummy/open' }
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
16
|
+
it 'signs a user in using switch_user' do
|
15
17
|
# can't access protected url
|
16
|
-
get
|
18
|
+
get '/dummy/protected'
|
17
19
|
expect(response).to be_redirect
|
18
20
|
|
19
21
|
get "/switch_user?scope_identifier=user_#{other_user.id}"
|
20
22
|
expect(response).to be_redirect
|
21
23
|
|
22
24
|
# now that we are logged in via switch_user we can access
|
23
|
-
get
|
25
|
+
get '/dummy/protected'
|
24
26
|
expect(response).to be_success
|
25
27
|
end
|
26
28
|
|
27
|
-
context
|
29
|
+
context 'using switch_back' do
|
28
30
|
before do
|
29
31
|
SwitchUser.switch_back = true
|
30
|
-
SwitchUser.controller_guard = ->(current_user,
|
32
|
+
SwitchUser.controller_guard = ->(current_user, _request, original_user) { current_user && current_user.admin? || original_user && original_user.admin? }
|
31
33
|
end
|
32
34
|
|
33
|
-
it
|
35
|
+
it 'can switch back to a different user through remember_user endpoint' do
|
34
36
|
# login
|
35
|
-
post
|
37
|
+
post '/login', params: { id: user.id }
|
36
38
|
follow_redirect!
|
37
39
|
|
38
40
|
# have SwitchUser remember us
|
39
|
-
get
|
40
|
-
expect(session[
|
41
|
+
get '/switch_user/remember_user', params: { remember: true }
|
42
|
+
expect(session['original_user_scope_identifier']).to be_present
|
41
43
|
|
42
44
|
# check that we can switch to another user
|
43
45
|
get "/switch_user?scope_identifier=user_#{other_user.id}"
|
44
|
-
expect(session[
|
46
|
+
expect(session['user_id']).to eq other_user.id
|
45
47
|
|
46
48
|
# logout
|
47
|
-
get
|
48
|
-
expect(session[
|
49
|
+
get '/logout'
|
50
|
+
expect(session['user_id']).to be_nil
|
49
51
|
|
50
52
|
# check that we can still switch to another user
|
51
53
|
get "/switch_user?scope_identifier=user_#{user.id}"
|
52
|
-
expect(session[
|
54
|
+
expect(session['user_id']).to eq user.id
|
53
55
|
|
54
56
|
# check that we can be un-remembered
|
55
|
-
get
|
56
|
-
expect(session[
|
57
|
+
get '/switch_user/remember_user', params: { remember: false }
|
58
|
+
expect(session['original_user']).to be_nil
|
57
59
|
end
|
58
60
|
|
59
|
-
it
|
61
|
+
it 'can switch back to a different user without hitting remember_user endpoint' do
|
60
62
|
# login
|
61
|
-
post
|
63
|
+
post '/login', params: { id: user.id }
|
62
64
|
follow_redirect!
|
63
65
|
|
64
66
|
# check that we can switch to another user
|
65
|
-
get "/switch_user?scope_identifier=user_#{other_user.id}", params: { :
|
66
|
-
expect(session[
|
67
|
-
expect(session[
|
67
|
+
get "/switch_user?scope_identifier=user_#{other_user.id}", params: { remember: true }
|
68
|
+
expect(session['user_id']).to eq other_user.id
|
69
|
+
expect(session['original_user_scope_identifier']).to_not be_nil
|
68
70
|
|
69
71
|
# logout
|
70
|
-
get
|
71
|
-
expect(session[
|
72
|
+
get '/logout'
|
73
|
+
expect(session['user_id']).to be_nil
|
72
74
|
|
73
75
|
# check that we can still switch to another user
|
74
76
|
get "/switch_user?scope_identifier=user_#{user.id}"
|
75
|
-
expect(session[
|
77
|
+
expect(session['user_id']).to eq user.id
|
76
78
|
|
77
79
|
# check that we can be un-remembered
|
78
|
-
get
|
79
|
-
expect(session[
|
80
|
+
get '/switch_user/remember_user', params: { remember: false }
|
81
|
+
expect(session['original_user']).to be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when non-default identifier' do
|
85
|
+
before do
|
86
|
+
SwitchUser.available_users_identifiers = { user: :email }
|
87
|
+
end
|
88
|
+
|
89
|
+
after do
|
90
|
+
SwitchUser.available_users_identifiers = { user: :id }
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'can switch back to a different user through remember_user endpoint' do
|
94
|
+
# login
|
95
|
+
post '/login', params: { id: user.id }
|
96
|
+
follow_redirect!
|
97
|
+
|
98
|
+
# have SwitchUser remember us
|
99
|
+
get '/switch_user/remember_user', params: { remember: true }
|
100
|
+
expect(session['original_user_scope_identifier']).to be_present
|
101
|
+
|
102
|
+
# check that we can switch to another user
|
103
|
+
get "/switch_user?scope_identifier=user_#{other_user.email}"
|
104
|
+
expect(session['user_id']).to eq other_user.id
|
105
|
+
|
106
|
+
# logout
|
107
|
+
get '/logout'
|
108
|
+
expect(session['user_id']).to be_nil
|
109
|
+
|
110
|
+
# check that we can still switch to another user
|
111
|
+
get "/switch_user?scope_identifier=user_#{user.email}"
|
112
|
+
expect(session['user_id']).to eq user.id
|
113
|
+
|
114
|
+
# check that we can be un-remembered
|
115
|
+
get '/switch_user/remember_user', params: { remember: false }
|
116
|
+
expect(session['original_user']).to be_nil
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'can switch back to a different user without hitting remember_user endpoint' do
|
120
|
+
# login
|
121
|
+
post '/login', params: { id: user.id }
|
122
|
+
follow_redirect!
|
123
|
+
|
124
|
+
# check that we can switch to another user
|
125
|
+
get "/switch_user?scope_identifier=user_#{other_user.email}", params: { remember: true }
|
126
|
+
expect(session['user_id']).to eq other_user.id
|
127
|
+
expect(session['original_user_scope_identifier']).to_not be_nil
|
128
|
+
|
129
|
+
# logout
|
130
|
+
get '/logout'
|
131
|
+
expect(session['user_id']).to be_nil
|
132
|
+
|
133
|
+
# check that we can still switch to another user
|
134
|
+
get "/switch_user?scope_identifier=user_#{user.email}"
|
135
|
+
expect(session['user_id']).to eq user.id
|
136
|
+
|
137
|
+
# check that we can be un-remembered
|
138
|
+
get '/switch_user/remember_user', params: { remember: false }
|
139
|
+
expect(session['original_user']).to be_nil
|
140
|
+
end
|
80
141
|
end
|
81
142
|
end
|
82
143
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'switch_user/provider/authlogic'
|
3
5
|
|
@@ -33,5 +35,5 @@ RSpec.describe SwitchUser::Provider::Authlogic do
|
|
33
35
|
let(:controller) { AuthlogicController.new }
|
34
36
|
let(:provider) { SwitchUser::Provider::Authlogic.new(controller) }
|
35
37
|
|
36
|
-
it_behaves_like
|
38
|
+
it_behaves_like 'a provider'
|
37
39
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'switch_user/provider/clearance'
|
3
5
|
|
@@ -19,5 +21,5 @@ RSpec.describe SwitchUser::Provider::Clearance do
|
|
19
21
|
let(:controller) { ClearanceController.new }
|
20
22
|
let(:provider) { SwitchUser::Provider::Clearance.new(controller) }
|
21
23
|
|
22
|
-
it_behaves_like
|
24
|
+
it_behaves_like 'a provider'
|
23
25
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'switch_user/provider/devise'
|
3
5
|
|
4
6
|
class FakeWardenSessionSerializer
|
5
7
|
attr_accessor :user_hash
|
6
8
|
|
7
|
-
|
8
9
|
def store(user, scope)
|
9
10
|
return unless user
|
10
11
|
user_hash[scope] = user
|
11
12
|
end
|
12
|
-
|
13
13
|
end
|
14
14
|
|
15
15
|
class FakeWarden
|
@@ -54,34 +54,34 @@ RSpec.describe SwitchUser::Provider::Devise do
|
|
54
54
|
let(:provider) { SwitchUser::Provider::Devise.new(controller) }
|
55
55
|
let(:user) { double(:user) }
|
56
56
|
|
57
|
-
it_behaves_like
|
57
|
+
it_behaves_like 'a provider'
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'can use alternate scopes' do
|
60
60
|
user = double(:user)
|
61
61
|
provider.login(user, :admin)
|
62
62
|
|
63
63
|
expect(provider.current_user(:admin)).to eq user
|
64
64
|
end
|
65
65
|
|
66
|
-
describe
|
66
|
+
describe '#login_exclusive' do
|
67
67
|
before do
|
68
|
-
allow(SwitchUser).to receive(:available_users).and_return(
|
68
|
+
allow(SwitchUser).to receive(:available_users).and_return(user: nil, admin: nil)
|
69
69
|
provider.login(user, :admin)
|
70
|
-
provider.login_exclusive(user, scope:
|
70
|
+
provider.login_exclusive(user, scope: 'user')
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'logs the user in' do
|
74
74
|
expect(provider.current_user(:user)).to eq user
|
75
75
|
end
|
76
76
|
|
77
|
-
it
|
77
|
+
it 'logs out other scopes' do
|
78
78
|
expect(provider.current_user(:admin)).to be_nil
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
describe
|
83
|
-
it
|
84
|
-
allow(SwitchUser).to receive(:available_users).and_return(
|
82
|
+
describe '#logout_all' do
|
83
|
+
it 'logs out users under all scopes' do
|
84
|
+
allow(SwitchUser).to receive(:available_users).and_return(user: nil, admin: nil)
|
85
85
|
provider.login(user, :admin)
|
86
86
|
provider.login(user, :user)
|
87
87
|
|
@@ -92,17 +92,17 @@ RSpec.describe SwitchUser::Provider::Devise do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
describe
|
96
|
-
it
|
97
|
-
allow(SwitchUser).to receive(:available_users).and_return(
|
95
|
+
describe '#all_current_users' do
|
96
|
+
it 'pulls users from an alternate scope' do
|
97
|
+
allow(SwitchUser).to receive(:available_users).and_return(user: nil, admin: nil)
|
98
98
|
provider.login(user, :admin)
|
99
99
|
|
100
100
|
expect(provider.current_users_without_scope).to eq [user]
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
describe
|
105
|
-
it
|
104
|
+
describe '#current_user?' do
|
105
|
+
it 'logs the user in' do
|
106
106
|
user = double(:user)
|
107
107
|
provider.login(user, :user)
|
108
108
|
|
data/spec/provider/dummy_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'switch_user/provider/dummy'
|
3
5
|
|
@@ -8,5 +10,5 @@ RSpec.describe SwitchUser::Provider::Session do
|
|
8
10
|
let(:controller) { SessionController.new }
|
9
11
|
let(:provider) { SwitchUser::Provider::Dummy.new(controller) }
|
10
12
|
|
11
|
-
it_behaves_like
|
13
|
+
it_behaves_like 'a provider'
|
12
14
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'switch_user/provider/restful_authentication'
|
3
5
|
|
@@ -13,5 +15,5 @@ RSpec.describe SwitchUser::Provider::RestfulAuthentication do
|
|
13
15
|
let(:controller) { RestfulAuthenticationController.new }
|
14
16
|
let(:provider) { SwitchUser::Provider::RestfulAuthentication.new(controller) }
|
15
17
|
|
16
|
-
it_behaves_like
|
18
|
+
it_behaves_like 'a provider'
|
17
19
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'switch_user/provider/session'
|
3
5
|
|
@@ -14,5 +16,5 @@ RSpec.describe SwitchUser::Provider::Session do
|
|
14
16
|
let(:controller) { SessionController.new }
|
15
17
|
let(:provider) { SwitchUser::Provider::Session.new(controller) }
|
16
18
|
|
17
|
-
it_behaves_like
|
19
|
+
it_behaves_like 'a provider'
|
18
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'switch_user/provider/sorcery'
|
3
5
|
|
@@ -20,5 +22,5 @@ RSpec.describe SwitchUser::Provider::Sorcery do
|
|
20
22
|
let(:controller) { SorceryController.new }
|
21
23
|
let(:provider) { SwitchUser::Provider::Sorcery.new(controller) }
|
22
24
|
|
23
|
-
it_behaves_like
|
25
|
+
it_behaves_like 'a provider'
|
24
26
|
end
|
data/spec/provider_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module SwitchUser
|
4
6
|
RSpec.describe Provider do
|
5
|
-
it
|
7
|
+
it 'initializes the provider' do
|
6
8
|
SwitchUser.provider = :dummy
|
7
9
|
expect(Provider.init(double(:controller))).to be_a(Provider::Dummy)
|
8
10
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
require 'capybara/rspec'
|
@@ -6,32 +8,32 @@ Capybara.app = MyApp::Application
|
|
6
8
|
|
7
9
|
require 'switch_user/rspec'
|
8
10
|
|
9
|
-
RSpec.feature
|
11
|
+
RSpec.feature 'SwitchUser::RSpecFeatureHelpers', type: :feature do
|
10
12
|
background do
|
11
|
-
@user = User.create!(email:
|
12
|
-
@client = Client.create!(email:
|
13
|
+
@user = User.create!(email: 'foo@bar.com', admin: true)
|
14
|
+
@client = Client.create!(email: 'foo@bar.com')
|
13
15
|
end
|
14
16
|
|
15
17
|
before(:example) do
|
16
|
-
allow(SwitchUser).to receive(:controller_guard).and_return(->(
|
18
|
+
allow(SwitchUser).to receive(:controller_guard).and_return(->(_current_user, _request) { true })
|
17
19
|
|
18
|
-
allow(SwitchUser).to receive(:available_users).and_return(
|
20
|
+
allow(SwitchUser).to receive(:available_users).and_return(user: -> { User.all })
|
19
21
|
|
20
|
-
allow(SwitchUser).to receive(:available_users_identifiers).and_return(
|
22
|
+
allow(SwitchUser).to receive(:available_users_identifiers).and_return(user: :id)
|
21
23
|
|
22
|
-
allow(SwitchUser).to receive(:available_users_names).and_return(
|
24
|
+
allow(SwitchUser).to receive(:available_users_names).and_return(user: :email)
|
23
25
|
end
|
24
26
|
|
25
|
-
scenario
|
26
|
-
allow(SwitchUser).to receive(:controller_guard).and_return(->(
|
27
|
+
scenario 'when controller_guard return false' do
|
28
|
+
allow(SwitchUser).to receive(:controller_guard).and_return(->(_current_user, _request) { false })
|
27
29
|
|
28
30
|
expect do
|
29
31
|
switch_user @user
|
30
32
|
end.not_to raise_error
|
31
33
|
end
|
32
34
|
|
33
|
-
scenario
|
34
|
-
allow(SwitchUser).to receive(:controller_guard).and_return(->(
|
35
|
+
scenario 'when controller_guard return false and controller call original available?' do
|
36
|
+
allow(SwitchUser).to receive(:controller_guard).and_return(->(_current_user, _request) { false })
|
35
37
|
|
36
38
|
allow_any_instance_of(SwitchUserController).to receive(:available?).and_call_original
|
37
39
|
|
@@ -40,73 +42,73 @@ RSpec.feature "SwitchUser::RSpecFeatureHelpers", type: :feature do
|
|
40
42
|
end.to raise_error ActionController::RoutingError, /Do not try to hack us/
|
41
43
|
end
|
42
44
|
|
43
|
-
scenario
|
45
|
+
scenario 'arg is @user, available_users is default, and available_users_identifiers is default' do
|
44
46
|
expect do
|
45
47
|
switch_user @user
|
46
48
|
end.not_to raise_error
|
47
49
|
end
|
48
50
|
|
49
|
-
scenario
|
50
|
-
allow(SwitchUser).to receive(:available_users_identifiers).and_return(
|
51
|
+
scenario 'arg is @user, available_users is default, and available_users_identifiers is {user: id}' do
|
52
|
+
allow(SwitchUser).to receive(:available_users_identifiers).and_return(user: :id)
|
51
53
|
|
52
54
|
expect do
|
53
55
|
switch_user @user
|
54
56
|
end.not_to raise_error
|
55
57
|
end
|
56
58
|
|
57
|
-
scenario
|
58
|
-
allow(SwitchUser).to receive(:available_users_identifiers).and_return(
|
59
|
-
allow(SwitchUser).to receive(:available_users_names).and_return(
|
59
|
+
scenario 'arg is @user, available_users is default, and available_users_identifiers is {:client => :id}' do
|
60
|
+
allow(SwitchUser).to receive(:available_users_identifiers).and_return(client: :id)
|
61
|
+
allow(SwitchUser).to receive(:available_users_names).and_return(client: :email)
|
60
62
|
|
61
63
|
expect do
|
62
64
|
switch_user @user
|
63
65
|
end.to raise_error SwitchUser::InvalidScope, /config.available_users_identifiers/
|
64
66
|
end
|
65
67
|
|
66
|
-
scenario
|
68
|
+
scenario 'arg is @client, available_users is default, and available_users_identifiers is default' do
|
67
69
|
expect do
|
68
70
|
switch_user @client
|
69
71
|
end.to raise_error SwitchUser::InvalidScope, /config.available_users/
|
70
72
|
end
|
71
73
|
|
72
|
-
scenario
|
73
|
-
allow(SwitchUser).to receive(:available_users).and_return(
|
74
|
+
scenario 'arg is @client, available_users is {:user => lambda { User.all }, :client => lambda {Client.all}}, and available_users_identifiers is default' do
|
75
|
+
allow(SwitchUser).to receive(:available_users).and_return(user: -> { User.all }, client: -> { Client.all })
|
74
76
|
|
75
77
|
expect do
|
76
78
|
switch_user @client
|
77
79
|
end.to raise_error SwitchUser::InvalidScope, /config.available_users_identifiers/
|
78
80
|
end
|
79
81
|
|
80
|
-
scenario
|
81
|
-
allow(SwitchUser).to receive(:available_users).and_return(
|
82
|
+
scenario 'arg is @client, available_users is {:user => lambda { User.all }, :client => lambda {Client.all}}, and available_users_identifiers is {:user => id, :client => id}' do
|
83
|
+
allow(SwitchUser).to receive(:available_users).and_return(user: -> { User.all }, client: -> { Client.all })
|
82
84
|
|
83
|
-
allow(SwitchUser).to receive(:available_users_identifiers).and_return(
|
84
|
-
allow(SwitchUser).to receive(:available_users_names).and_return(
|
85
|
+
allow(SwitchUser).to receive(:available_users_identifiers).and_return(user: :id, client: :id)
|
86
|
+
allow(SwitchUser).to receive(:available_users_names).and_return(user: :email, client: :email)
|
85
87
|
|
86
88
|
expect do
|
87
89
|
switch_user @client
|
88
90
|
end.not_to raise_error
|
89
91
|
end
|
90
92
|
|
91
|
-
scenario
|
93
|
+
scenario 'args is :user and @user.id, available_users is default, and available_users_identifiers is default' do
|
92
94
|
expect do
|
93
95
|
switch_user :user, @user.id
|
94
96
|
end.not_to raise_error
|
95
97
|
end
|
96
98
|
|
97
|
-
scenario
|
99
|
+
scenario 'arg is :client and @client.id, available_users is default, and available_users_identifiers is default' do
|
98
100
|
expect do
|
99
101
|
switch_user :client, @client.id
|
100
102
|
end.to raise_error SwitchUser::InvalidScope, /config.available_users/
|
101
103
|
end
|
102
104
|
|
103
|
-
scenario
|
105
|
+
scenario 'args is :user, available_users is default, and available_users_identifiers is default' do
|
104
106
|
expect do
|
105
107
|
switch_user :user
|
106
108
|
end.to raise_error SwitchUser::RSpecFeatureHelpers::InvalidArgument, /user_id is empty/
|
107
109
|
end
|
108
110
|
|
109
|
-
scenario
|
111
|
+
scenario 'args is :user and nil, available_users is default, and available_users_identifiers is default' do
|
110
112
|
expect do
|
111
113
|
switch_user :user, nil
|
112
114
|
end.to raise_error SwitchUser::RSpecFeatureHelpers::InvalidArgument, /user_id is empty/
|
@@ -118,10 +120,9 @@ RSpec.feature "SwitchUser::RSpecFeatureHelpers", type: :feature do
|
|
118
120
|
end.to raise_error SwitchUser::RSpecFeatureHelpers::InvalidArgument, /user_id is empty/
|
119
121
|
end
|
120
122
|
|
121
|
-
scenario
|
123
|
+
scenario 'args is :user and 0, available_users is default, and available_users_identifiers is default' do
|
122
124
|
expect do
|
123
125
|
switch_user :user, 0
|
124
126
|
end.not_to raise_error
|
125
127
|
end
|
126
|
-
|
127
128
|
end
|