diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 15:07:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 15:07:45 +0000 |
commit | 1219a9dce91f4edbc135dfc08299b4122b4825a8 (patch) | |
tree | e7d12a55d75a2d56e60d9527bef3724e3578866d /spec/models | |
parent | 1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae (diff) | |
download | gitlab-ce-1219a9dce91f4edbc135dfc08299b4122b4825a8.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/active_session_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/member_spec.rb | 100 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/user_preference_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 52 |
5 files changed, 82 insertions, 78 deletions
diff --git a/spec/models/active_session_spec.rb b/spec/models/active_session_spec.rb index bff3ac313c4..27a80f93566 100644 --- a/spec/models/active_session_spec.rb +++ b/spec/models/active_session_spec.rb @@ -165,10 +165,10 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do ActiveSession.set(user, request) Gitlab::Redis::SharedState.with do |redis| - expect(redis.scan_each.to_a).to match_array [ + expect(redis.scan_each.to_a).to include( "session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", "session:lookup:user:gitlab:#{user.id}" - ] + ) end end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 0e8ae320405..cd9d7c16f88 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -597,97 +597,49 @@ describe Member do end context 'when after_commit :update_highest_role' do - context 'with feature flag enabled' do - where(:member_type, :source_type) do - :project_member | :project - :group_member | :group - end + where(:member_type, :source_type) do + :project_member | :project + :group_member | :group + end - with_them do - describe 'create member' do - it 'initializes a new Members::UpdateHighestRoleService object' do - source = create(source_type) # source owner initializes a new service object too - user = create(:user) + with_them do + describe 'create member' do + it 'initializes a new Members::UpdateHighestRoleService object' do + source = create(source_type) # source owner initializes a new service object too + user = create(:user) - expect(Members::UpdateHighestRoleService).to receive(:new).with(user.id).and_call_original + expect(Members::UpdateHighestRoleService).to receive(:new).with(user.id).and_call_original - create(member_type, :guest, user: user, source_type => source) - end + create(member_type, :guest, user: user, source_type => source) end + end - context 'when member exists' do - let!(:member) { create(member_type) } - - describe 'update member' do - context 'when access level was changed' do - it 'initializes a new Members::UpdateHighestRoleService object' do - expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original - - member.update(access_level: Gitlab::Access::GUEST) - end - end - - context 'when access level was not changed' do - it 'does not initialize a new Members::UpdateHighestRoleService object' do - expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id) - - member.update(notification_level: NotificationSetting.levels[:disabled]) - end - end - end + context 'when member exists' do + let!(:member) { create(member_type) } - describe 'destroy member' do + describe 'update member' do + context 'when access level was changed' do it 'initializes a new Members::UpdateHighestRoleService object' do expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original - member.destroy + member.update(access_level: Gitlab::Access::GUEST) end end - end - end - end - - context 'with feature flag disabled' do - before do - stub_feature_flags(highest_role_callback: false) - end - - where(:member_type, :source_type) do - :project_member | :project - :group_member | :group - end - - with_them do - describe 'create member' do - it 'does not initialize a new Members::UpdateHighestRoleService object' do - source = create(source_type) - user = create(:user) - - expect(Members::UpdateHighestRoleService).not_to receive(:new).with(user.id) - - create(member_type, :guest, user: user, source_type => source) - end - end - context 'when member exists' do - let!(:member) { create(member_type) } - - describe 'update member' do - context 'when access level was changed' do - it 'does not initialize a new Members::UpdateHighestRoleService object' do - expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id) + context 'when access level was not changed' do + it 'does not initialize a new Members::UpdateHighestRoleService object' do + expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id) - member.update(access_level: Gitlab::Access::GUEST) - end + member.update(notification_level: NotificationSetting.levels[:disabled]) end end + end - describe 'destroy member' do - it 'does not initialize a new Members::UpdateHighestRoleService object' do - expect(Members::UpdateHighestRoleService).not_to receive(:new).with(member.user_id) + describe 'destroy member' do + it 'initializes a new Members::UpdateHighestRoleService object' do + expect(Members::UpdateHighestRoleService).to receive(:new).with(member.user_id).and_call_original - member.destroy - end + member.destroy end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 694c6935c1d..508098bfc39 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -827,7 +827,7 @@ describe Project do end it 'returns nil when no issue found' do - expect(project.get_issue(999, user)).to be_nil + expect(project.get_issue(non_existing_record_id, user)).to be_nil end it "returns nil when user doesn't have access" do diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb index 7884b87cc26..cf32d4eeca7 100644 --- a/spec/models/user_preference_spec.rb +++ b/spec/models/user_preference_spec.rb @@ -53,7 +53,7 @@ describe UserPreference do it 'returns the current notes filter' do user_preference.set_notes_filter(only_comments, issuable) - expect(user_preference.set_notes_filter(9999, issuable)).to eq(only_comments) + expect(user_preference.set_notes_filter(non_existing_record_id, issuable)).to eq(only_comments) end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f16b1fb136d..b21841ad034 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1221,6 +1221,10 @@ describe User, :do_not_mock_admin_mode do end it 'uses SecureRandom to generate the incoming email token' do + allow_next_instance_of(User) do |user| + allow(user).to receive(:update_highest_role) + end + expect(SecureRandom).to receive(:hex).and_return('3b8ca303') user = create(:user) @@ -4441,4 +4445,52 @@ describe User, :do_not_mock_admin_mode do end end end + + context 'when after_commit :update_highest_role' do + describe 'create user' do + it 'initializes a new Members::UpdateHighestRoleService object' do + expect_next_instance_of(Members::UpdateHighestRoleService) do |service| + expect(service).to receive(:execute) + end + + create(:user) + end + end + + context 'when user already exists' do + let!(:user) { create(:user) } + + describe 'update user' do + using RSpec::Parameterized::TableSyntax + + where(:attributes) do + [ + { state: 'blocked' }, + { ghost: true }, + { user_type: :alert_bot } + ] + end + + with_them do + context 'when state was changed' do + it 'initializes a new Members::UpdateHighestRoleService object' do + expect_next_instance_of(Members::UpdateHighestRoleService) do |service| + expect(service).to receive(:execute) + end + + user.update(attributes) + end + end + end + + context 'when state was not changed' do + it 'does not initialize a new Members::UpdateHighestRoleService object' do + expect(Members::UpdateHighestRoleService).not_to receive(:new) + + user.update(email: 'newmail@example.com') + end + end + end + end + end end |