2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-08 22:30:01 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe MergeRequests::AssignIssuesService do
|
2016-08-08 22:30:01 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-03-27 21:14:01 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-08-08 22:30:01 +00:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:merge_request) { create(:merge_request, :simple, source_project: project, author: user, description: "fixes #{issue.to_reference}") }
|
|
|
|
let(:service) { described_class.new(project, user, merge_request: merge_request) }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_developer(user)
|
2016-08-08 22:30:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds unassigned issues fixed in merge request' do
|
|
|
|
expect(service.assignable_issues.map(&:id)).to include(issue.id)
|
|
|
|
end
|
|
|
|
|
2017-05-04 12:11:15 +00:00
|
|
|
it 'ignores issues the user cannot update assignee on' do
|
|
|
|
project.team.truncate
|
2016-08-08 22:30:01 +00:00
|
|
|
|
|
|
|
expect(service.assignable_issues).to be_empty
|
|
|
|
end
|
|
|
|
|
2017-05-04 12:11:15 +00:00
|
|
|
it 'ignores issues already assigned to any user' do
|
|
|
|
issue.assignees = [create(:user)]
|
2016-08-08 22:30:01 +00:00
|
|
|
|
|
|
|
expect(service.assignable_issues).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores all issues unless current_user is merge_request.author' do
|
|
|
|
merge_request.update!(author: create(:user))
|
|
|
|
|
|
|
|
expect(service.assignable_issues).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts precomputed data for closes_issues' do
|
|
|
|
issue2 = create(:issue, project: project)
|
|
|
|
service2 = described_class.new(project,
|
|
|
|
user,
|
|
|
|
merge_request: merge_request,
|
|
|
|
closes_issues: [issue, issue2])
|
|
|
|
|
|
|
|
expect(service2.assignable_issues.count).to eq 2
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns these to the merge request owner' do
|
2017-05-04 12:11:15 +00:00
|
|
|
expect { service.execute }.to change { issue.assignees.first }.to(user)
|
2016-08-08 22:30:01 +00:00
|
|
|
end
|
2016-10-20 14:40:24 +00:00
|
|
|
|
|
|
|
it 'ignores external issues' do
|
|
|
|
external_issue = ExternalIssue.new('JIRA-123', project)
|
|
|
|
service = described_class.new(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
merge_request: merge_request,
|
|
|
|
closes_issues: [external_issue]
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(service.assignable_issues.count).to eq 0
|
|
|
|
end
|
2016-08-08 22:30:01 +00:00
|
|
|
end
|