diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-07-11 00:13:06 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-05-10 16:26:21 +0300 |
commit | b1012d986c4142d7c45d46fa70511ea5faa6150f (patch) | |
tree | b19d94d1ac47b6079bdd3cecb885dff5a3e0fdd2 /spec/lib/gitlab/dependency_linker | |
parent | 3f6d91c53c1bf99ce2e7dfeb9c25ef5f8149b72e (diff) |
Autolink package names in Gemfile
Diffstat (limited to 'spec/lib/gitlab/dependency_linker')
-rw-r--r-- | spec/lib/gitlab/dependency_linker/gemfile_linker_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/lib/gitlab/dependency_linker/gemfile_linker_spec.rb b/spec/lib/gitlab/dependency_linker/gemfile_linker_spec.rb new file mode 100644 index 00000000000..62e477e1de0 --- /dev/null +++ b/spec/lib/gitlab/dependency_linker/gemfile_linker_spec.rb @@ -0,0 +1,63 @@ +require 'rails_helper' + +describe Gitlab::DependencyLinker::GemfileLinker, lib: true do + 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' + + # Responders respond_to and respond_with + gem 'responders', '~> 2.0', :github => 'rails/responders' + + # Specify a sprockets version due to increased performance + # See https://gitlab.com/gitlab-org/gitlab-ce/issues/6069 + gem 'sprockets', '~> 3.6.0' + + # Default values for AR models + gem 'default_value_for', '~> 3.0.0' + CONTENT + end + + subject { Gitlab::Highlight.highlight(file_name, file_content) } + + def link(name, url) + %{<a href="#{url}" rel="noopener noreferrer" target="_blank">#{name}</a>} + 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', 'https://rubygems.org/gems/rails')) + expect(subject).to include(link('rails-deprecated_sanitizer', 'https://rubygems.org/gems/rails-deprecated_sanitizer')) + expect(subject).to include(link('responders', 'https://rubygems.org/gems/responders')) + expect(subject).to include(link('sprockets', 'https://rubygems.org/gems/sprockets')) + expect(subject).to include(link('default_value_for', 'https://rubygems.org/gems/default_value_for')) + end + + 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 + end +end |