-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51f520d
commit ddcc607
Showing
1 changed file
with
34 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,40 +212,52 @@ | |
email: '[email protected]') | ||
end | ||
|
||
it 'overwrites the saved values with the values from the authentication provider if true' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true) | ||
context 'value is true' do | ||
before do | ||
reg_method = instance_double(SettingGetter) | ||
allow(SettingGetter).to receive(:new).with(setting_name: 'ResyncOnLogin', provider: 'greenlight').and_return(reg_method) | ||
allow(reg_method).to receive(:call).and_return(true) | ||
end | ||
|
||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
it 'overwrites the saved values with the values from the authentication provider if true' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
get :create_user, params: { provider: 'openid_connect' } | ||
get :create_user, params: { provider: 'openid_connect' } | ||
|
||
user.reload | ||
expect(user.name).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['name']) | ||
expect(user.email).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['email']) | ||
end | ||
user.reload | ||
expect(user.name).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['name']) | ||
expect(user.email).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['email']) | ||
end | ||
|
||
it 'does not overwrite the saved values with the values from the authentication provider if false' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(false) | ||
it 'does not overwrite the role even if true' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true) | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
new_role = create(:role) | ||
user.update(role: new_role) | ||
|
||
get :create_user, params: { provider: 'openid_connect' } | ||
get :create_user, params: { provider: 'openid_connect' } | ||
|
||
user.reload | ||
expect(user.name).to eq('Example Name') | ||
expect(user.email).to eq('[email protected]') | ||
expect(user.reload.role).to eq(new_role) | ||
end | ||
end | ||
|
||
it 'does not overwrite the role even if true' do | ||
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true) | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
context 'value is false' do | ||
before do | ||
reg_method = instance_double(SettingGetter) | ||
allow(SettingGetter).to receive(:new).with(setting_name: 'ResyncOnLogin', provider: 'greenlight').and_return(reg_method) | ||
allow(reg_method).to receive(:call).and_return(false) | ||
end | ||
|
||
new_role = create(:role) | ||
user.update(role: new_role) | ||
it 'does not overwrite the saved values with the values from the authentication provider if false' do | ||
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect] | ||
|
||
get :create_user, params: { provider: 'openid_connect' } | ||
get :create_user, params: { provider: 'openid_connect' } | ||
|
||
expect(user.reload.role).to eq(new_role) | ||
user.reload | ||
expect(user.name).to eq('Example Name') | ||
expect(user.email).to eq('[email protected]') | ||
end | ||
end | ||
end | ||
|
||
|