summaryrefslogtreecommitdiff
path: root/spec/services/members
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2017-04-17 12:27:00 +0300
committerValery Sizov <valery@gitlab.com>2017-04-18 11:17:38 +0300
commit014aca5307b914da01fd96451a637c01ef437893 (patch)
tree1486478badc07f1deb7b42f672583b473788b1b8 /spec/services/members
parentc3bb21ff800699bed829a30c75fa81fd0d4dab8d (diff)
downloadgitlab-ce-014aca5307b914da01fd96451a637c01ef437893.tar.gz
Unassign all Issues and Merge Requests when member leaves team
Diffstat (limited to 'spec/services/members')
-rw-r--r--spec/services/members/authorized_destroy_service_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/services/members/authorized_destroy_service_spec.rb b/spec/services/members/authorized_destroy_service_spec.rb
new file mode 100644
index 00000000000..9912800da53
--- /dev/null
+++ b/spec/services/members/authorized_destroy_service_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe Members::AuthorizedDestroyService, services: true do
+ let(:user) { create(:user) }
+ let(:member_user) { create(:user) }
+ let(:project) { create(:empty_project, :public) }
+ let(:group) { create(:group, :public) }
+ let(:group_project) { create(:empty_project, :public, group: group) }
+
+ def number_of_assigned_issuables(user)
+ user.assigned_issues.count + user.assigned_merge_requests.count
+ end
+
+ context 'Group member' do
+ it "unassigns issues and merge requests" do
+ group.add_developer(member_user)
+
+ issue = create :issue, project: group_project, assignee: member_user
+ create :issue, assignee: member_user
+ merge_request = create :merge_request, target_project: group_project, source_project: group_project, assignee: member_user
+ create :merge_request, target_project: project, source_project: project, assignee: member_user
+
+ member = group.members.find_by(user_id: member_user.id)
+
+ expect{ described_class.new(member, member_user).execute }
+ .to change{ number_of_assigned_issuables(member_user) }.from(4).to(2)
+
+ expect(issue.reload.assignee_id).to be_nil
+ expect(merge_request.reload.assignee_id).to be_nil
+ end
+ end
+
+ context 'Project member' do
+ it "unassigns issues and merge requests" do
+ project.team << [member_user, :developer]
+
+ create :issue, project: project, assignee: member_user
+ create :merge_request, target_project: project, source_project: project, assignee: member_user
+
+ member = project.members.find_by(user_id: member_user.id)
+
+ expect{ described_class.new(member, member_user).execute }
+ .to change{ number_of_assigned_issuables(member_user) }.from(2).to(0)
+ end
+ end
+end