2017-04-17 05:27:00 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Members::AuthorizedDestroyService, services: true do
|
|
|
|
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)
|
2017-04-18 12:24:41 -04:00
|
|
|
Issue.assigned_to(user).count + MergeRequest.assigned_to(user).count
|
2017-04-17 05:27:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Group member' do
|
|
|
|
it "unassigns issues and merge requests" do
|
|
|
|
group.add_developer(member_user)
|
|
|
|
|
2017-05-04 16:55:36 -04:00
|
|
|
issue = create :issue, project: group_project, assignees: [member_user]
|
|
|
|
create :issue, assignees: [member_user]
|
2017-04-17 05:27:00 -04:00
|
|
|
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)
|
|
|
|
|
2017-04-19 11:17:46 -04:00
|
|
|
expect { described_class.new(member, member_user).execute }
|
|
|
|
.to change { number_of_assigned_issuables(member_user) }.from(4).to(2)
|
2017-04-17 05:27:00 -04:00
|
|
|
|
|
|
|
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]
|
|
|
|
|
2017-05-04 16:55:36 -04:00
|
|
|
create :issue, project: project, assignees: [member_user]
|
2017-04-17 05:27:00 -04:00
|
|
|
create :merge_request, target_project: project, source_project: project, assignee: member_user
|
|
|
|
|
|
|
|
member = project.members.find_by(user_id: member_user.id)
|
|
|
|
|
2017-04-19 11:17:46 -04:00
|
|
|
expect { described_class.new(member, member_user).execute }
|
|
|
|
.to change { number_of_assigned_issuables(member_user) }.from(2).to(0)
|
2017-04-17 05:27:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|