Commit 3978b5f9 authored by Michael Kozono's avatar Michael Kozono

Merge branch '341803-fix-project-and-group-milestone-references' into 'master'

Fix milestone references in group context

See merge request gitlab-org/gitlab!71269
parents 7f2aa7d8 c91b4985
......@@ -65,15 +65,11 @@ module EE
end
def group_context?(parent)
strong_memoize(:group_context) do
parent.is_a?(Group)
end
parent.is_a?(Group)
end
def project_context?(parent)
strong_memoize(:project_context) do
parent.is_a?(Project)
end
parent.is_a?(Project)
end
def references_in(text, pattern = ::Iteration.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,21 +61,15 @@ module Banzai
end
def valid_context?(parent)
strong_memoize(:valid_context) do
group_context?(parent) || project_context?(parent)
end
group_context?(parent) || project_context?(parent)
end
def group_context?(parent)
strong_memoize(:group_context) do
parent.is_a?(Group)
end
parent.is_a?(Group)
end
def project_context?(parent)
strong_memoize(:project_context) do
parent.is_a?(Project)
end
parent.is_a?(Project)
end
def references_in(text, pattern = Milestone.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