Commit dff3480d authored by Sean McGivern's avatar Sean McGivern Committed by Markus Koller

Fix issues list when due date parameter is invalid

With an invalid `due_date` param, `#by_due_date` would return `nil` and
so further methods would blow up. We should return an empty collection
for that.
parent 05eab17a
......@@ -97,6 +97,8 @@ class IssuesFinder < IssuableFinder
items.due_between(Date.today.beginning_of_month, Date.today.end_of_month)
elsif params.filter_by_due_next_month_and_previous_two_weeks?
items.due_between(Date.today - 2.weeks, (Date.today + 1.month).end_of_month)
else
items.none
end
end
......
---
title: Fix issues list when due date parameter is invalid
merge_request: 47524
author:
type: fixed
......@@ -831,6 +831,46 @@ RSpec.describe IssuesFinder do
let(:project_params) { { project_id: project.id } }
end
end
context 'filtering by due date' do
let_it_be(:issue_overdue) { create(:issue, project: project1, due_date: 2.days.ago) }
let_it_be(:issue_due_soon) { create(:issue, project: project1, due_date: 2.days.from_now) }
let(:scope) { 'all' }
let(:base_params) { { project_id: project1.id } }
context 'with param set to no due date' do
let(:params) { base_params.merge(due_date: Issue::NoDueDate.name) }
it 'returns issues with no due date' do
expect(issues).to contain_exactly(issue1)
end
end
context 'with param set to overdue' do
let(:params) { base_params.merge(due_date: Issue::Overdue.name) }
it 'returns overdue issues' do
expect(issues).to contain_exactly(issue_overdue)
end
end
context 'with param set to next month and previous two weeks' do
let(:params) { base_params.merge(due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name) }
it 'returns issues from the previous two weeks and next month' do
expect(issues).to contain_exactly(issue_overdue, issue_due_soon)
end
end
context 'with invalid param' do
let(:params) { base_params.merge(due_date: 'foo') }
it 'returns no issues' do
expect(issues).to be_empty
end
end
end
end
describe '#row_count', :request_store 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