1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'spec_helper'
describe MergeRequests::AssignIssuesService, services: true do
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
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
project.team << [user, :developer]
end
it 'finds unassigned issues fixed in merge request' do
expect(service.assignable_issues.map(&:id)).to include(issue.id)
end
it 'ignores issues already assigned to any user' do
issue.update!(assignee: create(:user))
expect(service.assignable_issues).to be_empty
end
it 'ignores issues the user cannot update assignee on' do
project.team.truncate
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
expect { service.execute }.to change { issue.reload.assignee }.to(user)
end
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
end