summaryrefslogtreecommitdiff
path: root/spec/models/members
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-16 03:11:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-16 03:11:08 +0000
commitf0abe9dd95232062d37f2f5bf832224272b7497c (patch)
treea32766ee919a7710d705f859a3303f1557bdd825 /spec/models/members
parente97635ea6c5bdb695188b3ad75edd5f5842387b4 (diff)
downloadgitlab-ce-f0abe9dd95232062d37f2f5bf832224272b7497c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/members')
-rw-r--r--spec/models/members/member_role_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/models/members/member_role_spec.rb b/spec/models/members/member_role_spec.rb
index b118a3c0968..4bf33eb1fce 100644
--- a/spec/models/members/member_role_spec.rb
+++ b/spec/models/members/member_role_spec.rb
@@ -78,4 +78,30 @@ RSpec.describe MemberRole, feature_category: :authentication_and_authorization d
end
end
end
+
+ describe 'callbacks' do
+ context 'for preventing deletion after member is associated' do
+ let_it_be(:member_role) { create(:member_role) }
+
+ subject(:destroy_member_role) { member_role.destroy } # rubocop: disable Rails/SaveBang
+
+ it 'allows deletion without any member associated' do
+ expect(destroy_member_role).to be_truthy
+ end
+
+ it 'prevent deletion when member is associated' do
+ create(:group_member, { group: member_role.namespace,
+ access_level: Gitlab::Access::DEVELOPER,
+ member_role: member_role })
+ member_role.members.reload
+
+ expect(destroy_member_role).to be_falsey
+ expect(member_role.errors.messages[:base])
+ .to(
+ include(s_("MemberRole|cannot be deleted because it is already assigned to a user. "\
+ "Please disassociate the member role from all users before deletion."))
+ )
+ end
+ end
+ end
end