2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-07-10 17:13:06 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::DependencyLinker::GemfileLinker do
|
2016-07-10 17:13:06 -04:00
|
|
|
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'
|
2017-05-12 11:29:25 -04:00
|
|
|
gem 'sprockets', '~> 3.6.0', git: 'https://gitlab.example.com/gems/sprockets'
|
2016-07-10 17:13:06 -04:00
|
|
|
gem 'default_value_for', '~> 3.0.0'
|
|
|
|
CONTENT
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { Gitlab::Highlight.highlight(file_name, file_content) }
|
|
|
|
|
|
|
|
def link(name, url)
|
2017-05-16 16:25:57 -04:00
|
|
|
%{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
|
2016-07-10 17:13:06 -04:00
|
|
|
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
|
|
|
|
|
2019-02-15 14:11:16 -05:00
|
|
|
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
|
|
|
|
|
2016-07-10 17:13:06 -04:00
|
|
|
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
|
2017-05-12 11:29:25 -04:00
|
|
|
|
|
|
|
it 'links Git repos' do
|
|
|
|
expect(subject).to include(link('https://gitlab.example.com/gems/sprockets', 'https://gitlab.example.com/gems/sprockets'))
|
|
|
|
end
|
2016-07-10 17:13:06 -04:00
|
|
|
end
|
|
|
|
end
|