Commit dac26dbe authored by Stan Hu's avatar Stan Hu

Merge branch 'fix_duplicit_epics_on_roadmap' into 'master'

Fix duplicit epics when filtering by milestone

See merge request gitlab-org/gitlab!52201
parents 4e1d6192 77e16614
......@@ -71,7 +71,7 @@ module EE
scope :in_parents, -> (parent_ids) { where(parent_id: parent_ids) }
scope :inc_group, -> { includes(:group) }
scope :in_selected_groups, -> (groups) { where(group_id: groups) }
scope :in_milestone, -> (milestone_id) { joins(:issues).where(issues: { milestone_id: milestone_id }) }
scope :in_milestone, -> (milestone_id) { joins(:issues).where(issues: { milestone_id: milestone_id }).distinct }
scope :in_issues, -> (issues) { joins(:epic_issues).where(epic_issues: { issue_id: issues }).distinct }
scope :has_parent, -> { where.not(parent_id: nil) }
scope :iid_starts_with, -> (query) { where("CAST(iid AS VARCHAR) LIKE ?", "#{sanitize_sql_like(query)}%") }
......
---
title: Fix duplicit epics on roadmap page when filtering by milestone
merge_request: 52201
author:
type: fixed
......@@ -398,7 +398,7 @@ RSpec.describe EpicsFinder do
params[:milestone_title] = ancestor_group_milestone.title
expect(epics(params)).to contain_exactly(ancestor_epic1, ancestor_epic1, subgroup_epic1)
expect(epics(params)).to contain_exactly(ancestor_epic1, subgroup_epic1)
end
it_behaves_like 'filtered by milestone', :project do
......
......@@ -7,7 +7,7 @@ RSpec.describe Epic do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let_it_be(:project) { create(:project, group: group) }
describe 'associations' do
subject { build(:epic) }
......@@ -61,6 +61,21 @@ RSpec.describe Epic do
expect(described_class.order_relative_position_on_board(board.id)).to eq([epic2, epic3, epic1, public_epic, confidential_epic])
end
end
describe '.in_milestone' do
let_it_be(:milestone) { create(:milestone, project: project) }
it 'returns epics which have an issue in the milestone' do
issue1 = create(:issue, project: project, milestone: milestone)
issue2 = create(:issue, project: project, milestone: milestone)
other_issue = create(:issue, project: project)
epic1 = create(:epic_issue, issue: issue1).epic
epic2 = create(:epic_issue, issue: issue2).epic
create(:epic_issue, issue: other_issue)
expect(described_class.in_milestone(milestone.id)).to match_array([epic1, epic2])
end
end
end
describe 'validations' 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