Commit 77e16614 authored by Jan Provaznik's avatar Jan Provaznik

Fix listing of epics by milestone

When epics are filtered by milestone, this is done through `join` issues
table. If an epic has multiple issues from the same milestone, then
there are duplicit Epic instances returned - we should use distinct list
in this case.
parent 8941d1d8
...@@ -71,7 +71,7 @@ module EE ...@@ -71,7 +71,7 @@ module EE
scope :in_parents, -> (parent_ids) { where(parent_id: parent_ids) } scope :in_parents, -> (parent_ids) { where(parent_id: parent_ids) }
scope :inc_group, -> { includes(:group) } scope :inc_group, -> { includes(:group) }
scope :in_selected_groups, -> (groups) { where(group_id: groups) } 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 :in_issues, -> (issues) { joins(:epic_issues).where(epic_issues: { issue_id: issues }).distinct }
scope :has_parent, -> { where.not(parent_id: nil) } scope :has_parent, -> { where.not(parent_id: nil) }
scope :iid_starts_with, -> (query) { where("CAST(iid AS VARCHAR) LIKE ?", "#{sanitize_sql_like(query)}%") } 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 ...@@ -398,7 +398,7 @@ RSpec.describe EpicsFinder do
params[:milestone_title] = ancestor_group_milestone.title 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 end
it_behaves_like 'filtered by milestone', :project do it_behaves_like 'filtered by milestone', :project do
......
...@@ -7,7 +7,7 @@ RSpec.describe Epic do ...@@ -7,7 +7,7 @@ RSpec.describe Epic do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:project) { create(:project, group: group) } let_it_be(:project) { create(:project, group: group) }
describe 'associations' do describe 'associations' do
subject { build(:epic) } subject { build(:epic) }
...@@ -61,6 +61,21 @@ RSpec.describe Epic do ...@@ -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]) expect(described_class.order_relative_position_on_board(board.id)).to eq([epic2, epic3, epic1, public_epic, confidential_epic])
end end
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 end
describe 'validations' do 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