@@ -7,188 +7,242 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
Timecop.freeze(Time.utc(2019,3,5)){example.run}
end
deffind(entity,opts)
described_class.new(entity,nil,opts).find
let(:base_opts)do
{
state: 'opened',
group_by: 'months'
}
end
it'raises an error for an invalid :issuable_type option'do
expect{find(nil,issuable_type: 'foo')}.toraise_error(described_class::InvalidIssuableTypeError,"Invalid `:issuable_type` option: `foo`. Allowed values are #{described_class::FINDERS.keys}!")
end
describe'#find'do
deffind(entity,opts)
described_class.new(entity,nil,opts).find
end
it'raises an error for an invalid entity object'do
expect{find(build(:user),issuable_type: 'issue')}.toraise_error(described_class::InvalidEntityError,'Entity class `User` is not supported. Supported classes are Project and Namespace!')
end
it'raises an error for an invalid :issuable_type option'do
expect{find(nil,issuable_type: 'foo')}.toraise_error(described_class::InvalidIssuableTypeError,"Invalid `:issuable_type` option: `foo`. Allowed values are #{described_class::FINDERS.keys}!")
end
it'raises an error for an invalid :group_by option'do
expect{find(nil,issuable_type: 'issue',group_by: 'foo')}.toraise_error(described_class::InvalidGroupByError,"Invalid `:group_by` option: `foo`. Allowed values are #{described_class::PERIODS.keys}!")
end
it'raises an error for an invalid entity object'do
expect{find(build(:user),issuable_type: 'issue')}.toraise_error(described_class::InvalidEntityError,'Entity class `User` is not supported. Supported classes are Project and Namespace!')
end
it'raises an error for an invalid :period_limit option'do
expect{find(build(:user),issuable_type: 'issue',group_by: 'months',period_limit: 'many')}.toraise_error(described_class::InvalidPeriodLimitError,"Invalid `:period_limit` option: `many`. Expected an integer!")
end
it'raises an error for an invalid :group_by option'do
expect{find(nil,issuable_type: 'issue',group_by: 'foo')}.toraise_error(described_class::InvalidGroupByError,"Invalid `:group_by` option: `foo`. Allowed values are #{described_class::PERIODS.keys}!")
@@ -29,8 +29,10 @@ RSpec.describe Gitlab::Insights::Reducers::CountPerPeriodReducer do
let(:expected)do
{
'January 2019'=>1,
'February 2019'=>1,
'March 2019'=>1
'February 2019'=>0,
'March 2019'=>1,
'April 2019'=>1,
'May 2019'=>0
}
end
...
...
@@ -39,7 +41,11 @@ RSpec.describe Gitlab::Insights::Reducers::CountPerPeriodReducer do
end
it'raises an error for an unknown :period_field option'do
expect{reduce(issuable_relation,'month',:foo)}.toraise_error(described_class::InvalidPeriodFieldError,"Invalid value for `period_field`: `foo`. Allowed values are #{described_class::VALID_PERIOD_FIELD}!")
expect{reduce(issuable_relation,'month',5,:foo)}.toraise_error(described_class::InvalidPeriodFieldError,"Invalid value for `period_field`: `foo`. Allowed values are #{described_class::VALID_PERIOD_FIELD}!")
end
it'raises an error for an unknown :period_limit option'do
expect{reduce(issuable_relation,'month',-1)}.toraise_error(described_class::InvalidPeriodLimitError,"Invalid value for `period_limit`: `-1`. Value must be greater than 0!")
end
it'returns issuables with only the needed fields'do