diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 072d07e0ed2..6eab8c5ee51 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -496,7 +496,7 @@ class IssuableFinder upcoming_ids = Milestone.upcoming_ids(projects, related_groups) items = items.left_joins_milestones.where(milestone_id: upcoming_ids) elsif filter_by_started_milestone? - items = items.left_joins_milestones.where('milestones.start_date <= NOW()') + items = items.left_joins_milestones.merge(Milestone.started) else items = items.with_milestone(params[:milestone_title]) end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index d6f94cad1fb..a3831ae3fa8 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -37,6 +37,7 @@ class Milestone < ActiveRecord::Base scope :active, -> { with_state(:active) } scope :closed, -> { with_state(:closed) } scope :for_projects, -> { where(group: nil).includes(:project) } + scope :started, -> { active.where('milestones.start_date <= CURRENT_DATE') } scope :for_projects_and_groups, -> (projects, groups) do projects = projects.compact if projects.is_a? Array diff --git a/changelogs/unreleased/only-counted-active-milestones-as-started.yml b/changelogs/unreleased/only-counted-active-milestones-as-started.yml new file mode 100644 index 00000000000..1a9c4b9023b --- /dev/null +++ b/changelogs/unreleased/only-counted-active-milestones-as-started.yml @@ -0,0 +1,5 @@ +--- +title: Only consider active milestones when using the special Started milestone filter +merge_request: +author: +type: fixed diff --git a/doc/user/project/milestones/index.md b/doc/user/project/milestones/index.md index e6033ca8655..a7d6144e3ec 100644 --- a/doc/user/project/milestones/index.md +++ b/doc/user/project/milestones/index.md @@ -92,7 +92,7 @@ When filtering by milestone, in addition to choosing a specific project mileston - **None**: Show issues or merge requests with no assigned milestone. - **Any**: Show issues or merge requests that have an assigned milestone. - **Upcoming**: Show issues or merge requests that have been assigned the open milestone that has the next upcoming due date (i.e. nearest due date in the future). -- **Started**: Show issues or merge requests that have an assigned milestone with a start date that is before today. +- **Started**: Show issues or merge requests that have an open assigned milestone with a start date that is before today. ## Milestone view diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 55efab7dec3..f74eb1364a6 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -220,6 +220,7 @@ describe IssuesFinder do let(:yesterday) { Date.today - 1.day } let(:tomorrow) { Date.today + 1.day } let(:two_days_ago) { Date.today - 2.days } + let(:three_days_ago) { Date.today - 3.days } let(:milestones) do [ @@ -227,6 +228,8 @@ describe IssuesFinder do create(:milestone, project: project_started_1_and_2, title: '1.0', start_date: two_days_ago), create(:milestone, project: project_started_1_and_2, title: '2.0', start_date: yesterday), create(:milestone, project: project_started_1_and_2, title: '3.0', start_date: tomorrow), + create(:milestone, :closed, project: project_started_1_and_2, title: '4.0', start_date: three_days_ago), + create(:milestone, :closed, project: project_started_8, title: '6.0', start_date: three_days_ago), create(:milestone, project: project_started_8, title: '7.0'), create(:milestone, project: project_started_8, title: '8.0', start_date: yesterday), create(:milestone, project: project_started_8, title: '9.0', start_date: tomorrow)