Commit b5775a56 authored by Manoj M J's avatar Manoj M J

Allow error-free deletion of orphaned group members

This fixes the bug where when an orphaned member
was destroyed, it errored out.

Changelog: fixed
parent 5d99db56
...@@ -8,7 +8,7 @@ class GroupMember < Member ...@@ -8,7 +8,7 @@ class GroupMember < Member
belongs_to :group, foreign_key: 'source_id' belongs_to :group, foreign_key: 'source_id'
alias_attribute :namespace_id, :source_id alias_attribute :namespace_id, :source_id
delegate :update_two_factor_requirement, to: :user delegate :update_two_factor_requirement, to: :user, allow_nil: true
# Make sure group member points only to group as it source # Make sure group member points only to group as it source
default_value_for :source_type, SOURCE_TYPE default_value_for :source_type, SOURCE_TYPE
......
...@@ -37,6 +37,10 @@ RSpec.describe GroupMember do ...@@ -37,6 +37,10 @@ RSpec.describe GroupMember do
end end
end end
describe 'delegations' do
it { is_expected.to delegate_method(:update_two_factor_requirement).to(:user).allow_nil }
end
describe '.access_level_roles' do describe '.access_level_roles' do
it 'returns Gitlab::Access.options_with_owner' do it 'returns Gitlab::Access.options_with_owner' do
expect(described_class.access_level_roles).to eq(Gitlab::Access.options_with_owner) expect(described_class.access_level_roles).to eq(Gitlab::Access.options_with_owner)
...@@ -93,6 +97,18 @@ RSpec.describe GroupMember do ...@@ -93,6 +97,18 @@ RSpec.describe GroupMember do
end end
end end
describe '#destroy' do
context 'for an orphaned member' do
let!(:orphaned_group_member) do
create(:group_member).tap { |member| member.update_column(:user_id, nil) }
end
it 'does not raise an error' do
expect { orphaned_group_member.destroy! }.not_to raise_error
end
end
end
describe '#after_accept_invite' do describe '#after_accept_invite' do
it 'calls #update_two_factor_requirement' do it 'calls #update_two_factor_requirement' do
email = 'foo@email.com' email = 'foo@email.com'
......
...@@ -58,6 +58,16 @@ RSpec.describe ProjectMember do ...@@ -58,6 +58,16 @@ RSpec.describe ProjectMember do
maintainer.destroy! maintainer.destroy!
expect(Event.recent.first).to be_left_action expect(Event.recent.first).to be_left_action
end end
context 'for an orphaned member' do
let!(:orphaned_project_member) do
owner.tap { |member| member.update_column(:user_id, nil) }
end
it 'does not raise an error' do
expect { orphaned_project_member.destroy! }.not_to raise_error
end
end
end end
describe '.import_team' do describe '.import_team' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment