Commit c91b4985 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix milestone references in group context

Fixes a bug where Markdown in Epics that contain both project and group
milestone references fails to render.

Changelog: fixed
parent 8896ceeb
......@@ -65,16 +65,12 @@ module EE
end
def group_context?(parent)
strong_memoize(:group_context) do
parent.is_a?(Group)
end
end
def project_context?(parent)
strong_memoize(:project_context) do
parent.is_a?(Project)
end
end
def references_in(text, pattern = ::Iteration.reference_pattern)
# We'll handle here the references that follow the `reference_pattern`.
......
......@@ -5,8 +5,6 @@ module Banzai
module References
# HTML filter that replaces milestone references with links.
class MilestoneReferenceFilter < AbstractReferenceFilter
include Gitlab::Utils::StrongMemoize
self.reference_type = :milestone
self.object_class = Milestone
......@@ -63,22 +61,16 @@ module Banzai
end
def valid_context?(parent)
strong_memoize(:valid_context) do
group_context?(parent) || project_context?(parent)
end
end
def group_context?(parent)
strong_memoize(:group_context) do
parent.is_a?(Group)
end
end
def project_context?(parent)
strong_memoize(:project_context) do
parent.is_a?(Project)
end
end
def references_in(text, pattern = Milestone.reference_pattern)
# We'll handle here the references that follow the `reference_pattern`.
......
......@@ -437,6 +437,19 @@ RSpec.describe Banzai::Filter::References::MilestoneReferenceFilter do
expect(reference_filter(act, context).to_html).to eq exp
end
end
context 'when referencing both project and group milestones' do
let(:milestone) { create(:milestone, project: project) }
let(:group_milestone) { create(:milestone, title: 'group_milestone', group: group) }
it 'links to valid references' do
links = reference_filter("See #{milestone.to_reference(full: true)} and #{group_milestone.to_reference}", context).css('a')
expect(links.length).to eq(2)
expect(links[0].attr('href')).to eq(urls.milestone_url(milestone))
expect(links[1].attr('href')).to eq(urls.milestone_url(group_milestone))
end
end
end
context 'when milestone is open' 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