Commit ad51ff40 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch '10324-weight-fix' into 'master'

Fix weight quick action to support 0 value

Closes #10324

See merge request gitlab-org/gitlab-ee!14432
parents ffadb3f4 179c0824
---
title: Fix weight quick action to support 0 value
merge_request: 14432
author:
type: fixed
......@@ -34,7 +34,7 @@ module EE
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", quick_action_target)
end
parse_params do |weight|
weight.to_i if weight.to_i > 0
weight.to_i if weight.to_i >= 0
end
command :weight do |weight|
@updates[:weight] = weight if weight
......
......@@ -27,6 +27,37 @@ describe Issues::UpdateService do
end
end
context 'updating weight' do
before do
project.add_maintainer(user)
issue.update(weight: 3)
end
context 'when weight is integer' do
it 'updates to the exact value' do
expect { update_issue(weight: 2) }.to change { issue.weight }.to(2)
end
end
context 'when weight is integer' do
it 'rounds the value down' do
expect { update_issue(weight: 1.8) }.to change { issue.weight }.to(1)
end
end
context 'when weight is zero' do
it 'sets the value to zero' do
expect { update_issue(weight: 0) }.to change { issue.weight }.to(0)
end
end
context 'when weight is a string' do
it 'sets the value to 0' do
expect { update_issue(weight: 'abc') }.to change { issue.weight }.to(0)
end
end
end
context 'updating other fields' do
it 'does not call epic#update_start_and_due_dates' do
expect(epic).not_to receive(:update_start_and_due_dates)
......
......@@ -682,19 +682,37 @@ describe QuickActions::InterpretService do
end
context 'issuable weights licensed' do
let(:issuable) { issue }
before do
stub_licensed_features(issue_weights: true)
end
it_behaves_like 'weight command' do
let(:weight) { 5 }
context 'weight' do
let(:content) { "/weight #{weight}" }
let(:issuable) { issue }
it_behaves_like 'weight command' do
let(:weight) { 5 }
end
it_behaves_like 'weight command' do
let(:weight) { 0 }
end
context 'when weight is negative' do
it 'does not populate weight' do
content = "/weight -10"
_, updates = service.execute(content, issuable)
expect(updates).to be_empty
end
end
end
it_behaves_like 'clear weight command' do
let(:content) { '/clear_weight' }
let(:issuable) { issue }
context 'clear_weight' do
it_behaves_like 'clear weight command' do
let(:content) { '/clear_weight' }
end
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