OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Adapt specs to work on actual users
Oliver Güntherce3b2fa41eee
diff --git a/spec/services/authentication/omniauth_service_spec.rb b/spec/services/authentication/omniauth_service_spec.rbindex 61413fe070d..2c1780136f5 100644--- a/spec/services/authentication/omniauth_service_spec.rb+++ b/spec/services/authentication/omniauth_service_spec.rb@@ -87,16 +87,10 @@ describe Authentication::OmniauthService dolet(:call) { instance.call }context 'with an active found user' do- let(:user) { build_stubbed(:user) }-- before do- expect(instance).to receive(:find_existing_user).and_return(user)- expect(Users::RegisterUserService).not_to receive(:new)- end+ let!(:user) { create(:user, login: '[email protected]', identity_url: 'google:123545') }it 'does not call register user service and logs in the user' do- # should update the user attributes- allow(user).to receive(:save)+ allow(Users::RegisterUserService).to receive(:new)expect(OpenProject::OmniAuth::Authorization).to(receive(:after_login!))@@ -107,51 +101,36 @@ describe Authentication::OmniauthService doexpect(call.result.firstname).to eq 'foo'expect(call.result.lastname).to eq 'bar'expect(call.result.mail).to eq '[email protected]'- expect(user).to have_received(:save)++ expect(Users::RegisterUserService).not_to have_received(:new)endendcontext 'without remapping allowed',with_settings: { oauth_allow_remapping_of_existing_users?: false } do+ let!(:user) { create(:user, login: '[email protected]') }+it 'does not look for the user by login' do- # Regular find- expect(User)- .to(receive(:find_by))- .with(identity_url: 'google:123545')- .and_return(nil)-- # Remap find- expect(User)- .not_to(receive(:find_by_login))- .with('[email protected]')-- call+ allow(Users::RegisterUserService).to receive(:new).and_call_original++ expect(call).not_to be_success+ expect(call.result.firstname).to eq 'foo'+ expect(call.result.lastname).to eq 'bar'+ expect(call.result.mail).to eq '[email protected]'+ expect(call.result).not_to eq user+ expect(call.result).to be_new_record+ expect(call.result.errors[:login]).to eq ['has already been taken.']++ expect(Users::RegisterUserService).to have_received(:new)endendcontext 'with an active user remapped',with_settings: { oauth_allow_remapping_of_existing_users?: true } do- let(:user) { build_stubbed(:user, identity_url: 'foo') }-- before do- # Regular find- expect(User)- .to(receive(:find_by))- .with(identity_url: 'google:123545')- .and_return(nil)-- # Remap find- expect(User)- .to(receive(:find_by_login))- .with('[email protected]')- .and_return(user)-- expect(Users::RegisterUserService).not_to receive(:new)- end+ let!(:user) { create(:user, identity_url: 'foo', login: '[email protected]') }it 'does not call register user service and logs in the user' do- # should update the user attributes- allow(user).to receive(:save)+ allow(Users::RegisterUserService).to receive(:new)expect(OpenProject::OmniAuth::Authorization).to(receive(:after_login!))@@ -162,7 +141,13 @@ describe Authentication::OmniauthService doexpect(call.result.firstname).to eq 'foo'expect(call.result.lastname).to eq 'bar'expect(call.result.mail).to eq '[email protected]'- expect(user).to have_received(:save)++ user.reload+ expect(user.firstname).to eq 'foo'+ expect(user.lastname).to eq 'bar'+ expect(user.identity_url).to eq 'google:123545'++ expect(Users::RegisterUserService).not_to have_received(:new)endend