diff options
Diffstat (limited to 'spec/lib/gitlab/markdown/label_reference_filter_spec.rb')
-rw-r--r-- | spec/lib/gitlab/markdown/label_reference_filter_spec.rb | 74 |
1 files changed, 27 insertions, 47 deletions
diff --git a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb index 9f898837466..e9f8ed277a5 100644 --- a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb @@ -3,15 +3,14 @@ require 'html/pipeline' module Gitlab::Markdown describe LabelReferenceFilter do - include ReferenceFilterSpecHelper + include FilterSpecHelper let(:project) { create(:empty_project) } let(:label) { create(:label, project: project) } - let(:reference) { "~#{label.id}" } + let(:reference) { label.to_reference } it 'requires project context' do - expect { described_class.call('Label ~123', {}) }. - to raise_error(ArgumentError, /:project/) + expect { described_class.call('') }.to raise_error(ArgumentError, /:project/) end %w(pre code a style).each do |elem| @@ -36,7 +35,7 @@ module Gitlab::Markdown link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) - expect(link).to eq urls.namespace_project_issues_url(project.namespace, project, label_name: label.name, only_path: true) + expect(link).to eq urls.namespace_project_issues_path(project.namespace, project, label_name: label.name) end it 'adds to the results hash' do @@ -70,7 +69,7 @@ module Gitlab::Markdown end it 'ignores invalid label IDs' do - exp = act = "Label ~#{label.id + 1}" + exp = act = "Label #{invalidate_reference(reference)}" expect(filter(act).to_html).to eq exp end @@ -78,7 +77,7 @@ module Gitlab::Markdown context 'String-based single-word references' do let(:label) { create(:label, name: 'gfm', project: project) } - let(:reference) { "~#{label.name}" } + let(:reference) { "#{Label.reference_prefix}#{label.name}" } it 'links to a valid reference' do doc = filter("See #{reference}") @@ -94,59 +93,40 @@ module Gitlab::Markdown end it 'ignores invalid label names' do - exp = act = "Label ~#{label.name.reverse}" + exp = act = "Label #{Label.reference_prefix}#{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) } + let(:label) { create(:label, name: 'gfm references', project: project) } + let(:reference) { label.to_reference(:name) } - 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}'" + it 'links to a valid reference' do + doc = filter("See #{reference}") - expect(filter(act).to_html).to eq exp - end + 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 - 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 '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.reference_prefix}"#{label.name.reverse}") - it 'ignores invalid label names' do - exp = act = %(Label ~"#{label.name.reverse}") + expect(filter(act).to_html).to eq exp + end + end - expect(filter(act).to_html).to eq exp - end + describe 'edge cases' do + it 'gracefully handles non-references matching the pattern' do + exp = act = '(format nil "~0f" 3.0) ; 3.0' + expect(filter(act).to_html).to eq exp end end end |