summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/markdown/external_link_filter_spec.rb
blob: c2ff4f80a42b4a0348aa898271c67c1c9ef8a2e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'spec_helper'

module Gitlab::Markdown
  describe ExternalLinkFilter do
    def filter(html, options = {})
      described_class.call(html, options)
    end

    it 'ignores elements without an href attribute' do
      exp = act = %q(<a id="ignored">Ignore Me</a>)
      expect(filter(act).to_html).to eq exp
    end

    it 'ignores non-HTTP(S) links' do
      exp = act = %q(<a href="irc://irc.freenode.net/gitlab">IRC</a>)
      expect(filter(act).to_html).to eq exp
    end

    it 'skips internal links' do
      internal = Gitlab.config.gitlab.url
      exp = act = %Q(<a href="#{internal}/sign_in">Login</a>)
      expect(filter(act).to_html).to eq exp
    end

    it 'adds rel="nofollow" to external links' do
      act = %q(<a href="https://google.com/">Google</a>)
      doc = filter(act)

      expect(doc.at_css('a')).to have_attribute('rel')
      expect(doc.at_css('a')['rel']).to eq 'nofollow'
    end
  end
end