gemfile_linker_spec.rb 2.16 KB
Newer Older
1 2
require 'rails_helper'

3
describe Gitlab::DependencyLinker::GemfileLinker do
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  describe '.support?' do
    it 'supports Gemfile' do
      expect(described_class.support?('Gemfile')).to be_truthy
    end

    it 'supports gems.rb' do
      expect(described_class.support?('gems.rb')).to be_truthy
    end

    it 'does not support other files' do
      expect(described_class.support?('Gemfile.lock')).to be_falsey
    end
  end

  describe '#link' do
    let(:file_name) { 'Gemfile' }

    let(:file_content) do
      <<-CONTENT.strip_heredoc
        source 'https://rubygems.org'

        gem "rails", '4.2.6', github: "rails/rails"
        gem 'rails-deprecated_sanitizer', '~> 1.0.3'
        gem 'responders', '~> 2.0', :github => 'rails/responders'
Douwe Maan's avatar
Douwe Maan committed
28
        gem 'sprockets', '~> 3.6.0', git: 'https://gitlab.example.com/gems/sprockets'
29 30 31 32 33 34 35
        gem 'default_value_for', '~> 3.0.0'
      CONTENT
    end

    subject { Gitlab::Highlight.highlight(file_name, file_content) }

    def link(name, url)
36
      %{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
37 38 39 40 41 42 43 44 45 46 47
    end

    it 'links sources' do
      expect(subject).to include(link('https://rubygems.org', 'https://rubygems.org'))
    end

    it 'links dependencies' do
      expect(subject).to include(link('rails-deprecated_sanitizer', 'https://rubygems.org/gems/rails-deprecated_sanitizer'))
      expect(subject).to include(link('default_value_for', 'https://rubygems.org/gems/default_value_for'))
    end

48 49 50 51 52 53
    it 'links to external dependencies' do
      expect(subject).to include(link('rails', 'https://github.com/rails/rails'))
      expect(subject).to include(link('responders', 'https://github.com/rails/responders'))
      expect(subject).to include(link('sprockets', 'https://gitlab.example.com/gems/sprockets'))
    end

54 55 56 57
    it 'links GitHub repos' do
      expect(subject).to include(link('rails/rails', 'https://github.com/rails/rails'))
      expect(subject).to include(link('rails/responders', 'https://github.com/rails/responders'))
    end
Douwe Maan's avatar
Douwe Maan committed
58 59 60 61

    it 'links Git repos' do
      expect(subject).to include(link('https://gitlab.example.com/gems/sprockets', 'https://gitlab.example.com/gems/sprockets'))
    end
62 63
  end
end