Commit fe04ddb4 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'fix-insights-period-field' into 'master'

Fix insights `period_field` parameter

See merge request gitlab-org/gitlab!38404
parents 1072170f 19f9e94b
---
title: Fix insights period_field parameter
merge_request: 38404
author:
type: fixed
......@@ -45,8 +45,8 @@ module Gitlab
raise InvalidPeriodError, "Invalid value for `period`: `#{period}`. Allowed values are #{VALID_PERIOD}!"
end
unless VALID_PERIOD_FIELDS[issuable_type].include?(period_field)
raise InvalidPeriodFieldError, "Invalid value for `period_field`: `#{period_field}`. Allowed values are #{VALID_PERIOD_FIELDS[issuable_type]}!"
unless VALID_PERIOD_FIELDS[issuable_type].include?(period_field.to_sym)
raise InvalidPeriodFieldError, "Invalid value for `period_field`: `#{period_field}`. Allowed values are #{VALID_PERIOD_FIELDS[issuable_type].join(', ')}!"
end
unless period_limit > 0
......
......@@ -71,7 +71,7 @@ RSpec.describe Gitlab::Insights::Reducers::CountPerPeriodReducer do
end
it 'raises an error for an unknown :period_field option' do
expect { reduce(issuable_relation, period: 'month', period_limit: 5, period_field: :foo) }.to raise_error(described_class::InvalidPeriodFieldError, "Invalid value for `period_field`: `foo`. Allowed values are #{described_class::VALID_PERIOD_FIELDS[:issue]}!")
expect { reduce(issuable_relation, period: 'month', period_limit: 5, period_field: :foo) }.to raise_error(described_class::InvalidPeriodFieldError, "Invalid value for `period_field`: `foo`. Allowed values are #{described_class::VALID_PERIOD_FIELDS[:issue].join(', ')}!")
end
it 'raises an error for an unknown :period_limit option' do
......@@ -106,6 +106,10 @@ RSpec.describe Gitlab::Insights::Reducers::CountPerPeriodReducer do
it 'returns issuables with only the needed fields' do
expect(reduce(issuable_relation, period: query[:group_by], period_field: :closed_at)).to eq(expected)
end
it 'works when string `period_field` is passed' do
expect(reduce(issuable_relation, period: query[:group_by], period_field: 'closed_at')).to eq(expected)
end
end
context 'with opened merge requests' do
......@@ -122,7 +126,7 @@ RSpec.describe Gitlab::Insights::Reducers::CountPerPeriodReducer do
end
it 'raises an error for an unknown :period_field option' do
expect { reduce(issuable_relation, period: 'month', period_limit: 5, period_field: :foo) }.to raise_error(described_class::InvalidPeriodFieldError, "Invalid value for `period_field`: `foo`. Allowed values are #{described_class::VALID_PERIOD_FIELDS[:merge_request]}!")
expect { reduce(issuable_relation, period: 'month', period_limit: 5, period_field: :foo) }.to raise_error(described_class::InvalidPeriodFieldError, "Invalid value for `period_field`: `foo`. Allowed values are #{described_class::VALID_PERIOD_FIELDS[:merge_request].join(', ')}!")
end
it 'returns issuables with only the needed fields' do
......
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