2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Issuable::BulkUpdateService, feature_category: :team_planning do
|
2021-03-08 18:12:59 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :repository, namespace: user.namespace) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def bulk_update(issuables, extra_params = {})
|
2016-09-13 17:45:13 +05:30
|
|
|
bulk_update_params = extra_params
|
2017-08-17 22:00:37 +05:30
|
|
|
.reverse_merge(issuable_ids: Array(issuables).map(&:id).join(','))
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
type = Array(issuables).first.model_name.param_key
|
2020-01-01 13:55:28 +05:30
|
|
|
Issuable::BulkUpdateService.new(parent, user, bulk_update_params).execute(type)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
shared_examples 'updates milestones' do
|
|
|
|
it 'succeeds' do
|
2019-10-12 21:52:04 +05:30
|
|
|
result = bulk_update(issuables, milestone_id: milestone.id)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(result.success?).to be_truthy
|
|
|
|
expect(result.payload[:count]).to eq(issuables.count)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it 'updates the issuables milestone' do
|
|
|
|
bulk_update(issuables, milestone_id: milestone.id)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
issuables.each do |issuable|
|
|
|
|
expect(issuable.reload.milestone).to eq(milestone)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2019-01-03 12:48:30 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
shared_examples 'updating labels' do
|
|
|
|
def create_issue_with_labels(labels)
|
|
|
|
create(:labeled_issue, project: project, labels: labels)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:issue_all_labels) { create_issue_with_labels([bug, regression, merge_requests]) }
|
|
|
|
let(:issue_bug_and_regression) { create_issue_with_labels([bug, regression]) }
|
|
|
|
let(:issue_bug_and_merge_requests) { create_issue_with_labels([bug, merge_requests]) }
|
|
|
|
let(:issue_no_labels) { create(:issue, project: project) }
|
|
|
|
let(:issues) { [issue_all_labels, issue_bug_and_regression, issue_bug_and_merge_requests, issue_no_labels] }
|
|
|
|
|
|
|
|
let(:add_labels) { [] }
|
|
|
|
let(:remove_labels) { [] }
|
|
|
|
|
|
|
|
let(:bulk_update_params) do
|
|
|
|
{
|
2022-10-11 01:57:18 +05:30
|
|
|
add_label_ids: add_labels.map(&:id),
|
2019-10-12 21:52:04 +05:30
|
|
|
remove_label_ids: remove_labels.map(&:id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
bulk_update(issues, bulk_update_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when add_label_ids are passed' do
|
|
|
|
let(:issues) { [issue_all_labels, issue_bug_and_merge_requests, issue_no_labels] }
|
|
|
|
let(:add_labels) { [bug, regression, merge_requests] }
|
|
|
|
|
|
|
|
it 'adds those label IDs to all issues passed' do
|
|
|
|
expect(issues.map(&:reload).map(&:label_ids)).to all(include(*add_labels.map(&:id)))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update issues not passed in' do
|
|
|
|
expect(issue_bug_and_regression.label_ids).to contain_exactly(bug.id, regression.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when remove_label_ids are passed' do
|
|
|
|
let(:issues) { [issue_all_labels, issue_bug_and_merge_requests, issue_no_labels] }
|
|
|
|
let(:remove_labels) { [bug, regression, merge_requests] }
|
|
|
|
|
|
|
|
it 'removes those label IDs from all issues passed' do
|
|
|
|
expect(issues.map(&:reload).map(&:label_ids)).to all(be_empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update issues not passed in' do
|
|
|
|
expect(issue_bug_and_regression.label_ids).to contain_exactly(bug.id, regression.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when add_label_ids and remove_label_ids are passed' do
|
|
|
|
let(:issues) { [issue_all_labels, issue_bug_and_merge_requests, issue_no_labels] }
|
|
|
|
let(:add_labels) { [bug] }
|
|
|
|
let(:remove_labels) { [merge_requests] }
|
|
|
|
|
|
|
|
it 'adds the label IDs to all issues passed' do
|
|
|
|
expect(issues.map(&:reload).map(&:label_ids)).to all(include(bug.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the label IDs from all issues passed' do
|
|
|
|
expect(issues.map(&:reload).flat_map(&:label_ids)).not_to include(merge_requests.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update issues not passed in' do
|
|
|
|
expect(issue_bug_and_regression.label_ids).to contain_exactly(bug.id, regression.id)
|
|
|
|
end
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
shared_examples 'scheduling cached group count clear' do
|
|
|
|
it 'schedules worker' do
|
|
|
|
expect(Issuables::ClearGroupsIssueCounterWorker).to receive(:perform_async)
|
|
|
|
|
|
|
|
bulk_update(issuables, params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'not scheduling cached group count clear' do
|
|
|
|
it 'does not schedule worker' do
|
|
|
|
expect(Issuables::ClearGroupsIssueCounterWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
bulk_update(issuables, params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
shared_examples 'bulk update service' do
|
|
|
|
it 'result count only includes authorized issuables' do
|
|
|
|
all_issues = issues + [create(:issue, project: create(:project, :private))]
|
|
|
|
result = bulk_update(all_issues, { assignee_ids: [user.id] })
|
|
|
|
|
|
|
|
expect(result[:count]).to eq(issues.count)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issuable_ids are passed as an array' do
|
|
|
|
it 'updates assignees' do
|
|
|
|
expect do
|
|
|
|
described_class.new(
|
|
|
|
parent,
|
|
|
|
user,
|
|
|
|
{ issuable_ids: issues.map(&:id), assignee_ids: [user.id] }
|
|
|
|
).execute('issue')
|
|
|
|
|
|
|
|
issues.each(&:reset)
|
|
|
|
end.to change { issues.flat_map(&:assignee_ids) }.from([]).to([user.id] * 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
context 'with issuables at a project level' do
|
2023-04-23 21:23:45 +05:30
|
|
|
let_it_be_with_reload(:issues) { create_list(:issue, 2, project: project) }
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:parent) { project }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it_behaves_like 'bulk update service'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
context 'with unpermitted attributes' do
|
|
|
|
let(:label) { create(:label, project: project) }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'does not update the issues' do
|
|
|
|
bulk_update(issues, label_ids: [label.id])
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(issues.map(&:reload).map(&:label_ids)).not_to include(label.id)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when issuable update service raises an ArgumentError' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Issues::UpdateService) do |update_service|
|
|
|
|
allow(update_service).to receive(:execute).and_raise(ArgumentError, 'update error')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error response' do
|
|
|
|
result = bulk_update(issues, add_label_ids: [])
|
2019-01-03 12:48:30 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(result).to be_error
|
|
|
|
expect(result.errors).to contain_exactly('update error')
|
|
|
|
expect(result.http_status).to eq(422)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'close issues' do
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'succeeds and returns the correct number of issues updated' do
|
|
|
|
result = bulk_update(issues, state_event: 'close')
|
2019-01-03 12:48:30 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(result.success?).to be_truthy
|
|
|
|
expect(result.payload[:count]).to eq(issues.count)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2019-01-03 12:48:30 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'closes all the issues passed' do
|
|
|
|
bulk_update(issues, state_event: 'close')
|
|
|
|
|
|
|
|
expect(project.issues.opened).to be_empty
|
|
|
|
expect(project.issues.closed).not_to be_empty
|
2019-01-03 12:48:30 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
it_behaves_like 'scheduling cached group count clear' do
|
|
|
|
let(:issuables) { issues }
|
|
|
|
let(:params) { { state_event: 'close' } }
|
|
|
|
end
|
2019-01-03 12:48:30 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'reopen issues' do
|
2023-04-23 21:23:45 +05:30
|
|
|
let_it_be_with_reload(:closed_issues) { create_list(:closed_issue, 2, project: project) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'succeeds and returns the correct number of issues updated' do
|
2023-04-23 21:23:45 +05:30
|
|
|
result = bulk_update(closed_issues, state_event: 'reopen')
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(result.success?).to be_truthy
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(result.payload[:count]).to eq(closed_issues.count)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'reopens all the issues passed' do
|
2023-04-23 21:23:45 +05:30
|
|
|
bulk_update(closed_issues, state_event: 'reopen')
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(project.issues.closed).to be_empty
|
|
|
|
expect(project.issues.opened).not_to be_empty
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
it_behaves_like 'scheduling cached group count clear' do
|
2023-04-23 21:23:45 +05:30
|
|
|
let(:issuables) { closed_issues }
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:params) { { state_event: 'reopen' } }
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'updating merge request assignee' do
|
|
|
|
let(:merge_request) { create(:merge_request, target_project: project, source_project: project, assignees: [user]) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
context 'when the new assignee ID is a valid user' do
|
|
|
|
it 'succeeds' do
|
|
|
|
new_assignee = create(:user)
|
|
|
|
project.add_developer(new_assignee)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
result = bulk_update(merge_request, assignee_ids: [user.id, new_assignee.id])
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(result.success?).to be_truthy
|
|
|
|
expect(result.payload[:count]).to eq(1)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'updates the assignee to the user ID passed' do
|
|
|
|
assignee = create(:user)
|
|
|
|
project.add_developer(assignee)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
expect { bulk_update(merge_request, assignee_ids: [assignee.id]) }
|
|
|
|
.to change { merge_request.reload.assignee_ids }.from([user.id]).to([assignee.id])
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context "when the new assignee ID is #{IssuableFinder::Params::NONE}" do
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'unassigns the issues' do
|
2020-04-22 19:07:51 +05:30
|
|
|
expect { bulk_update(merge_request, assignee_ids: [IssuableFinder::Params::NONE]) }
|
2019-09-30 21:07:59 +05:30
|
|
|
.to change { merge_request.reload.assignee_ids }.to([])
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when the new assignee IDs array is empty' do
|
|
|
|
it 'removes all assignees' do
|
2019-09-30 21:07:59 +05:30
|
|
|
expect { bulk_update(merge_request, assignee_ids: []) }
|
2023-04-23 21:23:45 +05:30
|
|
|
.to change(merge_request.assignees, :count).by(-1)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'updating issue assignee' do
|
|
|
|
let(:issue) { create(:issue, project: project, assignees: [user]) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
context 'when the new assignee ID is a valid user' do
|
|
|
|
it 'succeeds' do
|
|
|
|
new_assignee = create(:user)
|
|
|
|
project.add_developer(new_assignee)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
result = bulk_update(issue, assignee_ids: [new_assignee.id])
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(result.success?).to be_truthy
|
|
|
|
expect(result.payload[:count]).to eq(1)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'updates the assignee to the user ID passed' do
|
|
|
|
assignee = create(:user)
|
|
|
|
project.add_developer(assignee)
|
|
|
|
expect { bulk_update(issue, assignee_ids: [assignee.id]) }
|
|
|
|
.to change { issue.reload.assignees.first }.from(user).to(assignee)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context "when the new assignee ID is #{IssuableFinder::Params::NONE}" do
|
2019-09-30 21:07:59 +05:30
|
|
|
it "unassigns the issues" do
|
2020-04-22 19:07:51 +05:30
|
|
|
expect { bulk_update(issue, assignee_ids: [IssuableFinder::Params::NONE.to_s]) }
|
2019-09-30 21:07:59 +05:30
|
|
|
.to change { issue.reload.assignees.count }.from(1).to(0)
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when the new assignee IDs array is empty' do
|
|
|
|
it 'removes all assignees' do
|
2019-09-30 21:07:59 +05:30
|
|
|
expect { bulk_update(issue, assignee_ids: []) }
|
2023-04-23 21:23:45 +05:30
|
|
|
.to change(issue.assignees, :count).by(-1)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'updating milestones' do
|
2019-10-12 21:52:04 +05:30
|
|
|
let(:issuables) { [create(:issue, project: project)] }
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it_behaves_like 'updates milestones'
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
it_behaves_like 'not scheduling cached group count clear' do
|
|
|
|
let(:params) { { milestone_id: milestone.id } }
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'updating labels' do
|
|
|
|
let(:bug) { create(:label, project: project) }
|
|
|
|
let(:regression) { create(:label, project: project) }
|
|
|
|
let(:merge_requests) { create(:label, project: project) }
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
it_behaves_like 'updating labels'
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'subscribe to issues' do
|
|
|
|
let(:issues) { create_list(:issue, 2, project: project) }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'subscribes the given user' do
|
|
|
|
bulk_update(issues, subscription_event: 'subscribe')
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(issues).to all(be_subscribed(user, project))
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'unsubscribe from issues' do
|
|
|
|
let(:issues) do
|
|
|
|
create_list(:closed_issue, 2, project: project) do |issue|
|
2021-01-03 14:25:43 +05:30
|
|
|
issue.subscriptions.create!(user: user, project: project, subscribed: true)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unsubscribes the given user' do
|
|
|
|
bulk_update(issues, subscription_event: 'unsubscribe')
|
|
|
|
|
|
|
|
issues.each do |issue|
|
|
|
|
expect(issue).not_to be_subscribed(user, project)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe 'updating issues from external project' do
|
|
|
|
it 'updates only issues that belong to the parent project' do
|
|
|
|
issue1 = create(:issue, project: project)
|
|
|
|
issue2 = create(:issue, project: create(:project))
|
|
|
|
result = bulk_update([issue1, issue2], assignee_ids: [user.id])
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(result.success?).to be_truthy
|
|
|
|
expect(result.payload[:count]).to eq(1)
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
expect(issue1.reload.assignees).to eq([user])
|
|
|
|
expect(issue2.reload.assignees).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
context 'with issuables at a group level' do
|
2021-03-08 18:12:59 +05:30
|
|
|
let_it_be(:group) { create(:group) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
let(:parent) { group }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_reporter(user)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it_behaves_like 'bulk update service' do
|
|
|
|
let_it_be_with_reload(:issues) { create_list(:issue, 2, project: create(:project, group: group)) }
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe 'updating milestones' do
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:milestone) { create(:milestone, group: group) }
|
2019-10-12 21:52:04 +05:30
|
|
|
let(:project) { create(:project, :repository, group: group) }
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
context 'when issues' do
|
|
|
|
let(:issue1) { create(:issue, project: project) }
|
|
|
|
let(:issue2) { create(:issue, project: project) }
|
|
|
|
let(:issuables) { [issue1, issue2] }
|
|
|
|
|
|
|
|
it_behaves_like 'updates milestones'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when merge requests' do
|
|
|
|
let(:merge_request1) { create(:merge_request, source_project: project, source_branch: 'branch-1') }
|
|
|
|
let(:merge_request2) { create(:merge_request, source_project: project, source_branch: 'branch-2') }
|
|
|
|
let(:issuables) { [merge_request1, merge_request2] }
|
|
|
|
|
|
|
|
it_behaves_like 'updates milestones'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'updating labels' do
|
|
|
|
let(:project) { create(:project, :repository, group: group) }
|
|
|
|
let(:bug) { create(:group_label, group: group) }
|
|
|
|
let(:regression) { create(:group_label, group: group) }
|
|
|
|
let(:merge_requests) { create(:group_label, group: group) }
|
|
|
|
|
|
|
|
it_behaves_like 'updating labels'
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe 'with issues from external group' do
|
|
|
|
it 'updates issues that belong to the parent group or descendants' do
|
|
|
|
issue1 = create(:issue, project: create(:project, group: group))
|
|
|
|
issue2 = create(:issue, project: create(:project, group: create(:group)))
|
|
|
|
issue3 = create(:issue, project: create(:project, group: create(:group, parent: group)))
|
|
|
|
milestone = create(:milestone, group: group)
|
|
|
|
result = bulk_update([issue1, issue2, issue3], milestone_id: milestone.id)
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(result.success?).to be_truthy
|
|
|
|
expect(result.payload[:count]).to eq(2)
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
expect(issue1.reload.milestone).to eq(milestone)
|
|
|
|
expect(issue2.reload.milestone).to be_nil
|
|
|
|
expect(issue3.reload.milestone).to eq(milestone)
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
context 'when no parent is provided' do
|
|
|
|
it 'returns an unscoped update error' do
|
|
|
|
result = described_class.new(nil, user, { assignee_ids: [user.id], issuable_ids: [] }).execute('issue')
|
|
|
|
|
|
|
|
expect(result).to be_error
|
|
|
|
expect(result.errors).to contain_exactly(_('A parent must be provided when bulk updating issuables'))
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|