diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 09:09:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 09:09:51 +0300 |
commit | a59d305223365cb31bb670f134383d6ff316a13e (patch) | |
tree | f3be1afa29fca783ec0e94eaba41a4884d146ef8 /spec | |
parent | 19ae126005d36803c1d273334c3eac91881c071c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/dashboard/help_spec.rb | 2 | ||||
-rw-r--r-- | spec/helpers/members_helper_spec.rb | 11 | ||||
-rw-r--r-- | spec/migrations/remove_orphaned_invited_members_spec.rb | 55 |
3 files changed, 67 insertions, 1 deletions
diff --git a/spec/features/dashboard/help_spec.rb b/spec/features/dashboard/help_spec.rb index 3f425001447..73377453ba3 100644 --- a/spec/features/dashboard/help_spec.rb +++ b/spec/features/dashboard/help_spec.rb @@ -11,7 +11,7 @@ RSpec.describe 'Dashboard Help' do it 'renders correctly markdown' do visit help_page_path("administration/raketasks/maintenance") - expect(page).to have_content('Gather information about GitLab and the system it runs on') + expect(page).to have_content('Gather GitLab and system information') node = find('.documentation h2 a#user-content-check-gitlab-configuration') expect(node[:href]).to eq '#check-gitlab-configuration' diff --git a/spec/helpers/members_helper_spec.rb b/spec/helpers/members_helper_spec.rb index 169c8707bf4..946ffcddae7 100644 --- a/spec/helpers/members_helper_spec.rb +++ b/spec/helpers/members_helper_spec.rb @@ -22,6 +22,17 @@ describe MembersHelper do it { expect(remove_member_message(group_member_invite)).to eq "Are you sure you want to revoke the invitation for #{group_member_invite.invite_email} to join the #{group.name} group?" } it { expect(remove_member_message(group_member_request)).to eq "Are you sure you want to deny #{requester.name}'s request to join the #{group.name} group?" } it { expect(remove_member_message(group_member_request, user: requester)).to eq "Are you sure you want to withdraw your access request for the #{group.name} group?" } + + context 'an accepted user invitation with no user associated' do + before do + group_member_invite.update(invite_email: "#{SecureRandom.hex}@example.com", invite_token: nil, user_id: nil) + end + + it 'logs an exception and shows orphaned status' do + expect(Gitlab::ErrorTracking).to receive(:track_exception).with(anything, hash_including(:member_id, :invite_email, :invite_accepted_at)) + expect(remove_member_message(group_member_invite)).to eq "Are you sure you want to remove this orphaned member from the #{group.name} group and any subresources?" + end + end end describe '#remove_member_title' do diff --git a/spec/migrations/remove_orphaned_invited_members_spec.rb b/spec/migrations/remove_orphaned_invited_members_spec.rb new file mode 100644 index 00000000000..0ed4c15428a --- /dev/null +++ b/spec/migrations/remove_orphaned_invited_members_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20200424050250_remove_orphaned_invited_members.rb') + +describe RemoveOrphanedInvitedMembers do + let(:members_table) { table(:members) } + let(:users_table) { table(:users) } + let(:namespaces_table) { table(:namespaces) } + let(:projects_table) { table(:projects) } + + let!(:user1) { users_table.create!(name: 'user1', email: 'user1@example.com', projects_limit: 1) } + let!(:user2) { users_table.create!(name: 'user2', email: 'user2@example.com', projects_limit: 1) } + let!(:group) { namespaces_table.create!(type: 'Group', name: 'group', path: 'group') } + let!(:project) { projects_table.create!(name: 'project', path: 'project', namespace_id: group.id) } + + let!(:member1) { create_member(user_id: user1.id, source_type: 'Project', source_id: project.id, access_level: 10) } + let!(:member2) { create_member(user_id: user2.id, source_type: 'Group', source_id: group.id, access_level: 20) } + + let!(:invited_member1) do + create_member(user_id: nil, source_type: 'Project', source_id: project.id, + invite_token: SecureRandom.hex, invite_accepted_at: Time.now, + access_level: 20) + end + let!(:invited_member2) do + create_member(user_id: nil, source_type: 'Group', source_id: group.id, + invite_token: SecureRandom.hex, invite_accepted_at: Time.now, + access_level: 20) + end + + let!(:orphaned_member1) do + create_member(user_id: nil, source_type: 'Project', source_id: project.id, + invite_accepted_at: Time.now, access_level: 30) + end + let!(:orphaned_member2) do + create_member(user_id: nil, source_type: 'Group', source_id: group.id, + invite_accepted_at: Time.now, access_level: 20) + end + + it 'removes orphaned invited members but keeps current members' do + expect { migrate! }.to change { members_table.count }.from(6).to(4) + + expect(members_table.all.pluck(:id)).to contain_exactly(member1.id, member2.id, invited_member1.id, invited_member2.id) + end + + def create_member(options) + members_table.create!( + { + notification_level: 0, + ldap: false, + override: false + }.merge(options) + ) + end +end |