Commit fc4a9c46 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '338607_fix_reference_pattern_for_iterations' into 'master'

Fix reference pattern for iterations

See merge request gitlab-org/gitlab!68350
parents 7953189a 4176fa75
......@@ -120,8 +120,8 @@ module EE
\d+(?!\S\w)\b # Integer-based iteration id, or
) |
(?<iteration_name>
[^"\s]+\b | # String-based single-word iteration title, or
"[^"]+" # String-based multi-word iteration surrounded in quotes
[^"\s\<]+\b | # String-based single-word iteration title, or
"[^"]+" # String-based multi-word iteration surrounded in quotes
)
)
}x.freeze
......
......@@ -92,6 +92,11 @@ RSpec.describe Banzai::Filter::References::IterationReferenceFilter do
expect(doc.to_html).to match(%r(\(<a.+>#{iteration.reference_link_text}</a>\.\)))
end
it 'links with adjacent html tags' do
doc = reference_filter("Iteration <p>#{reference}</p>.")
expect(doc.to_html).to match(%r(<p><a.+>#{iteration.reference_link_text}</a></p>))
end
it 'ignores invalid iteration names' do
exp = act = "Iteration #{Iteration.reference_prefix}#{iteration.name.reverse}"
......
......@@ -91,6 +91,51 @@ RSpec.describe Iteration do
end
end
describe '.reference_pattern' do
subject { described_class.reference_pattern }
let(:captures) { subject.match(reference).named_captures }
context 'when iteration id is provided' do
let(:reference) { 'gitlab-org/gitlab-ce*iteration:123' }
it 'correctly detects the iteration' do
expect(captures).to eq(
'namespace' => 'gitlab-org',
'project' => 'gitlab-ce',
'iteration_id' => '123',
'iteration_name' => nil
)
end
end
context 'when iteration name is provided' do
let(:reference) { 'gitlab-org/gitlab-ce*iteration:my-iteration' }
it 'correctly detects the iteration' do
expect(captures).to eq(
'namespace' => 'gitlab-org',
'project' => 'gitlab-ce',
'iteration_id' => nil,
'iteration_name' => 'my-iteration'
)
end
end
context 'when reference includes tags' do
let(:reference) { '<p>gitlab-org/gitlab-ce*iteration:my-iteration</p>' }
it 'correctly detects the iteration' do
expect(captures).to eq(
'namespace' => 'gitlab-org',
'project' => 'gitlab-ce',
'iteration_id' => nil,
'iteration_name' => 'my-iteration'
)
end
end
end
describe '.filter_by_state' do
let_it_be(:closed_iteration) { create(:iteration, :closed, :skip_future_date_validation, group: group, start_date: 8.days.ago, due_date: 2.days.ago) }
let_it_be(:current_iteration) { create(:iteration, :current, :skip_future_date_validation, group: group, start_date: 1.day.ago, due_date: 6.days.from_now) }
......
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