Commit f6693f40 authored by Jarka Košanová's avatar Jarka Košanová

Merge branch '218395-bulk-editing-health-status-be' into 'master'

Add epic and health status attributes to BulkUpdateService

See merge request gitlab-org/gitlab!32875
parents c080db73 b900ea1d
...@@ -40,9 +40,13 @@ module Issuable ...@@ -40,9 +40,13 @@ module Issuable
private private
def permitted_attrs(type) def permitted_attrs(type)
attrs = %i(state_event milestone_id assignee_id assignee_ids add_label_ids remove_label_ids subscription_event) attrs = %i(state_event milestone_id add_label_ids remove_label_ids subscription_event)
if type == 'issue' issuable_specific_attrs(type, attrs)
end
def issuable_specific_attrs(type, attrs)
if type == 'issue' || type == 'merge_request'
attrs.push(:assignee_ids) attrs.push(:assignee_ids)
else else
attrs.push(:assignee_id) attrs.push(:assignee_id)
......
...@@ -13,6 +13,13 @@ module EE ...@@ -13,6 +13,13 @@ module EE
super super
end end
override :issuable_specific_attrs
def issuable_specific_attrs(type, attrs)
return super unless type == 'issue'
super.push(:health_status, :epic)
end
end end
end end
end end
---
title: Add support for bulk editing health status and epic on issues
merge_request: 32875
author:
type: added
...@@ -3,15 +3,104 @@ ...@@ -3,15 +3,104 @@
require 'spec_helper' require 'spec_helper'
describe Issuable::BulkUpdateService do describe Issuable::BulkUpdateService do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project1) { create(:project, :repository, group: group) }
let_it_be(:project2) { create(:project, :repository, group: group) }
subject { described_class.new(parent, user, params).execute(type) }
shared_examples 'updates issuables attribute' do |attribute|
it 'succeeds and returns the correct number of issuables updated' do
expect(subject[:success]).to be_truthy
expect(subject[:count]).to eq(issuables.count)
issuables.each do |issuable|
expect(issuable.reload.send(attribute)).to eq(new_value)
end
end
end
shared_examples 'does not update issuables attribute' do |attribute|
it 'does not update issuables' do
issuables.each do |issuable|
expect { subject }.not_to change { issuable.send(attribute) }
end
end
end
context 'with issues' do
let_it_be(:type) { 'issue' }
let_it_be(:parent) { group }
let(:issue1) { create(:issue, project: project1, health_status: :at_risk, epic: epic) }
let(:issue2) { create(:issue, project: project2, health_status: :at_risk, epic: epic) }
let(:epic) { create(:epic, group: group) }
let(:epic2) { create(:epic, group: group) }
let(:issuables) { [issue1, issue2] }
before do
group.add_reporter(user)
end
context 'updating health status and epic' do
let(:params) do
{
issuable_ids: issuables.map(&:id),
health_status: :on_track,
epic: epic2
}
end
context 'when features are enabled' do
before do
stub_licensed_features(epics: true, issuable_health_status: true)
end
it 'succeeds and returns the correct number of issuables updated' do
expect(subject[:success]).to be_truthy
expect(subject[:count]).to eq(issuables.count)
issuables.each do |issuable|
issuable.reload
expect(issuable.epic).to eq(epic2)
expect(issuable.health_status).to eq('on_track')
end
end
end
context 'when features are disabled' do
before do
stub_licensed_features(epics: false, issuable_health_status: false)
end
it_behaves_like 'does not update issuables attribute', :health_status
it_behaves_like 'does not update issuables attribute', :epic
end
context 'when user can not update issues' do
before do
group.add_guest(user)
end
it_behaves_like 'does not update issuables attribute', :health_status
it_behaves_like 'does not update issuables attribute', :epic
end
context 'when user can not admin epic' do
let(:epic3) { create(:epic, group: create(:group)) }
let(:params) { { issuable_ids: issuables.map(&:id), epic: epic3 } }
it_behaves_like 'does not update issuables attribute', :epic
end
end
end
context 'with epics' do context 'with epics' do
subject { described_class.new(group, user, params).execute('epic') } let_it_be(:type) { 'epic' }
let_it_be(:parent) { group }
let(:epic1) { create(:epic, group: group, labels: [label1]) } let(:epic1) { create(:epic, group: group, labels: [label1]) }
let(:epic2) { create(:epic, group: group, labels: [label1]) } let(:epic2) { create(:epic, group: group, labels: [label1]) }
let(:label1) { create(:group_label, group: group) }
let_it_be(:label1) { create(:group_label, group: group) }
before do before do
group.add_reporter(user) group.add_reporter(user)
...@@ -19,8 +108,8 @@ describe Issuable::BulkUpdateService do ...@@ -19,8 +108,8 @@ describe Issuable::BulkUpdateService do
end end
describe 'updating labels' do describe 'updating labels' do
let(:label2) { create(:group_label, group: group, title: 'Bug') } let_it_be(:label2) { create(:group_label, group: group, title: 'Bug') }
let(:label3) { create(:group_label, group: group, title: 'suggestion') } let_it_be(:label3) { create(:group_label, group: group, title: 'suggestion') }
let(:issuables) { [epic1, epic2] } let(:issuables) { [epic1, epic2] }
let(:params) do let(:params) do
...@@ -32,14 +121,9 @@ describe Issuable::BulkUpdateService do ...@@ -32,14 +121,9 @@ describe Issuable::BulkUpdateService do
end end
context 'when epics are enabled' do context 'when epics are enabled' do
it 'updates epic labels' do let(:new_value) { [label2, label3] }
expect(subject[:success]).to be_truthy
expect(subject[:count]).to eq(issuables.count)
issuables.each do |issuable| it_behaves_like 'updates issuables attribute', :labels
expect(issuable.reload.labels).to eq([label2, label3])
end
end
end end
context 'when epics are disabled' do context 'when epics are disabled' do
...@@ -47,11 +131,7 @@ describe Issuable::BulkUpdateService do ...@@ -47,11 +131,7 @@ describe Issuable::BulkUpdateService do
stub_licensed_features(epics: false) stub_licensed_features(epics: false)
end end
it 'does not update labels' do it_behaves_like 'does not update issuables attribute', :labels
issuables.each do |issuable|
expect { subject }.not_to change { issuable.labels }
end
end
end end
context 'when issuable_ids contain external epics' do context 'when issuable_ids contain external epics' do
......
...@@ -81,7 +81,7 @@ describe Issues::UpdateService do ...@@ -81,7 +81,7 @@ describe Issues::UpdateService do
end end
end end
context 'when weight is integer' do context 'when weight is float' do
it 'rounds the value down' do it 'rounds the value down' do
expect { update_issue(weight: 1.8) }.to change { issue.weight }.to(1) expect { update_issue(weight: 1.8) }.to change { issue.weight }.to(1)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment