mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-22 11:06:10 +10:00
Add name-based referencing to LabelReferenceFilter
This commit is contained in:
@@ -21,24 +21,6 @@ module Gitlab::Markdown
|
||||
end
|
||||
end
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
||||
expect(doc.css('a').first.attr('href')).to eq urls.
|
||||
namespace_project_issues_url(project.namespace, project, label_name: label.name)
|
||||
end
|
||||
|
||||
it 'links with adjacent text' do
|
||||
doc = filter("Label (#{reference}.)")
|
||||
expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\)))
|
||||
end
|
||||
|
||||
it 'ignores invalid label IDs' do
|
||||
exp = act = "Label ~#{label.id + 1}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
|
||||
it 'includes default classes' do
|
||||
doc = filter("Label #{reference}")
|
||||
expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-label'
|
||||
@@ -68,5 +50,100 @@ module Gitlab::Markdown
|
||||
expect(doc.css('a span').first.attr('style')).to match(/\Abackground-color: #\h{6}; color: #\h{6}\z/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'Integer-based references' do
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
||||
expect(doc.css('a').first.attr('href')).to eq urls.
|
||||
namespace_project_issues_url(project.namespace, project, label_name: label.name)
|
||||
end
|
||||
|
||||
it 'links with adjacent text' do
|
||||
doc = filter("Label (#{reference}.)")
|
||||
expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\)))
|
||||
end
|
||||
|
||||
it 'ignores invalid label IDs' do
|
||||
exp = act = "Label ~#{label.id + 1}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'String-based single-word references' do
|
||||
let(:label) { create(:label, name: 'gfm', project: project) }
|
||||
let(:reference) { "~#{label.name}" }
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
||||
expect(doc.css('a').first.attr('href')).to eq urls.
|
||||
namespace_project_issues_url(project.namespace, project, label_name: label.name)
|
||||
expect(doc.text).to eq 'See gfm'
|
||||
end
|
||||
|
||||
it 'links with adjacent text' do
|
||||
skip 'FIXME (rspeicher): This will fail, because a period and parentheses are both currently valid in label names.'
|
||||
doc = filter("Label (#{reference}.)")
|
||||
expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\)))
|
||||
end
|
||||
|
||||
it 'ignores invalid label names' do
|
||||
exp = act = "Label ~#{label.name.reverse}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'String-based multi-word references in quotes' do
|
||||
let(:label) { create(:label, name: 'gfm references', project: project) }
|
||||
|
||||
context 'in single quotes' do
|
||||
let(:reference) { "~'#{label.name}'" }
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
||||
expect(doc.css('a').first.attr('href')).to eq urls.
|
||||
namespace_project_issues_url(project.namespace, project, label_name: label.name)
|
||||
expect(doc.text).to eq 'See gfm references'
|
||||
end
|
||||
|
||||
it 'links with adjacent text' do
|
||||
doc = filter("Label (#{reference}.)")
|
||||
expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\)))
|
||||
end
|
||||
|
||||
it 'ignores invalid label names' do
|
||||
exp = act = "Label ~'#{label.name.reverse}'"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'in double quotes' do
|
||||
let(:reference) { %(~"#{label.name}") }
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
||||
expect(doc.css('a').first.attr('href')).to eq urls.
|
||||
namespace_project_issues_url(project.namespace, project, label_name: label.name)
|
||||
expect(doc.text).to eq 'See gfm references'
|
||||
end
|
||||
|
||||
it 'links with adjacent text' do
|
||||
doc = filter("Label (#{reference}.)")
|
||||
expect(doc.to_html).to match(%r(\(<a.+><span.+>#{label.name}</span></a>\.\)))
|
||||
end
|
||||
|
||||
it 'ignores invalid label names' do
|
||||
exp = act = %(Label ~"#{label.name.reverse}")
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user