diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-04-27 18:54:13 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-04-30 16:35:25 -0400 |
commit | aa2cc670fe2c9de772c82d90df4ee2d8a77c23fc (patch) | |
tree | 403c34f8589864232db009a4960c7041d3a456c4 /spec | |
parent | 2d9edcada5135d1f72a2c284e93d8e5b18e00008 (diff) | |
download | gitlab-ce-aa2cc670fe2c9de772c82d90df4ee2d8a77c23fc.tar.gz |
Add Gitlab::Markdown::AutolinkFilter
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/markdown/autolink_filter_spec.rb | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/spec/lib/gitlab/markdown/autolink_filter_spec.rb b/spec/lib/gitlab/markdown/autolink_filter_spec.rb new file mode 100644 index 00000000000..83fee123330 --- /dev/null +++ b/spec/lib/gitlab/markdown/autolink_filter_spec.rb @@ -0,0 +1,98 @@ +require 'spec_helper' + +module Gitlab::Markdown + describe AutolinkFilter do + let(:link) { 'http://about.gitlab.com/' } + + def filter(html, options = {}) + described_class.call(html, options) + end + + it 'does nothing when :autolink is false' do + exp = act = link + expect(filter(act, autolink: false).to_html).to eq exp + end + + it 'does nothing with non-link text' do + exp = act = 'This text contains no links to autolink' + expect(filter(act).to_html).to eq exp + end + + context 'Rinku schemes' do + it 'autolinks http' do + doc = filter("See #{link}") + expect(doc.at_css('a').text).to eq link + expect(doc.at_css('a')['href']).to eq link + end + + it 'autolinks https' do + link = 'https://google.com/' + doc = filter("See #{link}") + + expect(doc.at_css('a').text).to eq link + expect(doc.at_css('a')['href']).to eq link + end + + it 'autolinks ftp' do + link = 'ftp://ftp.us.debian.org/debian/' + doc = filter("See #{link}") + + expect(doc.at_css('a').text).to eq link + expect(doc.at_css('a')['href']).to eq link + end + + it 'accepts link_attr options' do + doc = filter("See #{link}", link_attr: {class: 'custom'}) + + expect(doc.at_css('a')['class']).to eq 'custom' + end + + described_class::IGNORE_PARENTS.each do |elem| + it "ignores valid links contained inside '#{elem}' element" do + exp = act = "<#{elem}>See #{link}</#{elem}>" + expect(filter(act).to_html).to eq exp + end + end + end + + context 'other schemes' do + let(:link) { 'foo://bar.baz/' } + + it 'autolinks smb' do + link = 'smb:///Volumes/shared/foo.pdf' + doc = filter("See #{link}") + + expect(doc.at_css('a').text).to eq link + expect(doc.at_css('a')['href']).to eq link + end + + it 'autolinks irc' do + link = 'irc://irc.freenode.net/git' + doc = filter("See #{link}") + + expect(doc.at_css('a').text).to eq link + expect(doc.at_css('a')['href']).to eq link + end + + it 'does not include trailing punctuation' do + doc = filter("See #{link}.") + expect(doc.at_css('a').text).to eq link + + doc = filter("See #{link}, ok?") + expect(doc.at_css('a').text).to eq link + end + + it 'accepts link_attr options' do + doc = filter("See #{link}", link_attr: {class: 'custom'}) + expect(doc.at_css('a')['class']).to eq 'custom' + end + + described_class::IGNORE_PARENTS.each do |elem| + it "ignores valid links contained inside '#{elem}' element" do + exp = act = "<#{elem}>See #{link}</#{elem}>" + expect(filter(act).to_html).to eq exp + end + end + end + end +end |