diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-10-11 20:20:38 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-10-11 20:20:38 +0300 |
commit | d57d892e3fd4d73a477ba5c1b0049864f7c9e6b2 (patch) | |
tree | 40e6f028bd2769b405099c742956ebf4260929e7 /spec/services | |
parent | 9db841127bef1509d32ae5f3ff2458923c84a19d (diff) | |
parent | 6606642f8f352267d9f645778a789b79d98a6ca8 (diff) |
Merge branch 'assign-issues-for-merge-request-18876' into 'master'
Ability to bulk assign issues to author of merge request
## What does this MR do?
Provides a link to auto-assign issues to the author of a merge request, when they are mentioned as being closed by the MR.
## Are there points in the code the reviewer needs to double check?
## Why was this MR needed?
To help avoid working on a MR without having assigned related issues to self
## What are the relevant issue numbers?
Fixes #18876
## Screenshots (if relevant)
![ScreenShot-P216](/uploads/1af5e71a0a0ff0a60c5d7b54c0e09d9c/ScreenShot-P216.png)
## Tasks
- [x] Refactor or move away from using `BulkUpdateService`
- [x] ~~Consider alternate link message when only a subset of issues will be assigned~~
- [x] Minimize repeated calls to expensive `closes_issues` method
- [x] Move away from using inflector for pluralization and fix flash message
- [x] Change auth `before_action` and fallback to error flash message
- [x] Shouldn't overwrite current assignee if one exists
## Does this MR meet the acceptance criteria?
- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- [x] ~~API support added~~
- Tests
- [x] Added for this feature/bug
- [x] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
See merge request !5725
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/merge_requests/assign_issues_service_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/services/merge_requests/assign_issues_service_spec.rb b/spec/services/merge_requests/assign_issues_service_spec.rb new file mode 100644 index 00000000000..7aeb95a15ea --- /dev/null +++ b/spec/services/merge_requests/assign_issues_service_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe MergeRequests::AssignIssuesService, services: true do + let(:user) { create(:user) } + let(:project) { create(:project, :public) } + 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 +end |