Commit d661a72d authored by Eugenia Grieff's avatar Eugenia Grieff

Add health status attribute to bulk update service

- Modify BulkUpdateService to accept the attribute
health_status
- Add specs for bulk updating issues health status
at the project and the group level
parent 64dc299f
......@@ -40,13 +40,7 @@ module Issuable
private
def permitted_attrs(type)
attrs = %i(state_event milestone_id assignee_id assignee_ids add_label_ids remove_label_ids subscription_event)
if type == 'issue'
attrs.push(:assignee_ids)
else
attrs.push(:assignee_id)
end
%i(state_event assignee_ids milestone_id add_label_ids remove_label_ids subscription_event)
end
def find_issuables(parent, model_class, ids)
......
......@@ -13,6 +13,18 @@ module EE
super
end
override :permitted_attrs
def permitted_attrs(type)
case type
when 'issue'
super.push(:health_status)
when 'epic'
super.push(:assignee_id)
else
super
end
end
end
end
end
---
title: Add health status attribute to bulk update service
merge_request: 32875
author:
type: added
......@@ -3,15 +3,78 @@
require 'spec_helper'
describe Issuable::BulkUpdateService do
let(:user) { create(:user) }
let(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
context 'with issues' do
subject { described_class.new(parent, user, params).execute('issue') }
let_it_be(:project1) { create(:project, :repository, group: group) }
let_it_be(:project2) { create(:project, :repository, group: group) }
let_it_be(:issue1) { create(:issue, project: project1) }
let_it_be(:issue2) { create(:issue, project: project2) }
let_it_be(:issue3) { create(:issue, project: project1) }
describe 'updating health status' do
shared_examples 'updates health status' do
it 'succeeds and returns the correct number of issues updated' do
expect(subject[:success]).to be_truthy
expect(subject[:count]).to eq(2)
issues.each do |issue|
expect(issue.reload.health_status).to eq("on_track")
end
end
end
context 'when issuable_health_status feature is disabled' do
let_it_be(:parent) { project1 }
let_it_be(:issues) { [issue1, issue2] }
let_it_be(:params) { { issuable_ids: issues.map(&:id), health_status: 1 } }
before do
group.add_reporter(user)
stub_licensed_features(issuable_health_status: false)
end
it 'does not update health status' do
issues.each do |issue|
expect { subject }.not_to change { issue.health_status }
end
end
end
context 'when issuable_health_status feature is enabled' do
let(:issues) { [issue1, issue3] }
let(:params) { { issuable_ids: issues.map(&:id), health_status: 1 } }
before do
group.add_reporter(user)
stub_licensed_features(issuable_health_status: true)
end
context 'with issuables at the project level' do
let(:parent) { project1 }
it_behaves_like 'updates health status'
end
context 'with issuables at the group level' do
let(:parent) { group }
let(:issues) { [issue1, issue2] }
it_behaves_like 'updates health status'
end
end
end
end
context 'with epics' do
subject { described_class.new(group, user, params).execute('epic') }
let(:epic1) { 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
group.add_reporter(user)
......@@ -19,8 +82,8 @@ describe Issuable::BulkUpdateService do
end
describe 'updating labels' do
let(:label2) { create(:group_label, group: group, title: 'Bug') }
let(:label3) { create(:group_label, group: group, title: 'suggestion') }
let_it_be(:label2) { create(:group_label, group: group, title: 'Bug') }
let_it_be(:label3) { create(:group_label, group: group, title: 'suggestion') }
let(:issuables) { [epic1, epic2] }
let(:params) do
......@@ -70,4 +133,12 @@ describe Issuable::BulkUpdateService do
end
end
end
def bulk_update(parent, issuables, extra_params = {})
bulk_update_params = extra_params
.reverse_merge(issuable_ids: Array(issuables).map(&:id).join(','))
type = Array(issuables).first.model_name.param_key
Issuable::BulkUpdateService.new(parent, user, bulk_update_params).execute(type)
end
end
......@@ -81,7 +81,7 @@ describe Issues::UpdateService do
end
end
context 'when weight is integer' do
context 'when weight is float' do
it 'rounds the value down' do
expect { update_issue(weight: 1.8) }.to change { issue.weight }.to(1)
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