Merge branch '46193-fix-big-estimate' into 'master'

Resolve "Estimating a large amount results in a server error 500"

Closes #46193

See merge request gitlab-org/gitlab-ce!18964
This commit is contained in:
Rémy Coutable 2018-05-17 17:23:32 +00:00
commit 4609a1268d
3 changed files with 22 additions and 0 deletions

View File

@ -53,6 +53,10 @@ module TimeTrackable
Gitlab::TimeTrackingFormatter.output(time_estimate)
end
def time_estimate=(val)
val.is_a?(Integer) ? super([val, Gitlab::Database::MAX_INT_VALUE].min) : super(val)
end
private
def touchable?

View File

@ -0,0 +1,5 @@
---
title: Fixes 500 error on /estimate BIG_VALUE
merge_request: 18964
author: Jacopo Beschi @jacopo-beschi
type: fixed

View File

@ -266,6 +266,19 @@ describe Issuable do
end
end
describe '#time_estimate=' do
it 'coerces the value below Gitlab::Database::MAX_INT_VALUE' do
expect { issue.time_estimate = 100 }.to change { issue.time_estimate }.to(100)
expect { issue.time_estimate = Gitlab::Database::MAX_INT_VALUE + 100 }.to change { issue.time_estimate }.to(Gitlab::Database::MAX_INT_VALUE)
end
it 'skips coercion for not Integer values' do
expect { issue.time_estimate = nil }.to change { issue.time_estimate }.to(nil)
expect { issue.time_estimate = 'invalid time' }.not_to raise_error(StandardError)
expect { issue.time_estimate = 22.33 }.not_to raise_error(StandardError)
end
end
describe '#to_hook_data' do
let(:builder) { double }