2018-09-06 09:48:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe BlobPresenter, :seed_helper do
|
2018-12-23 07:34:35 +00:00
|
|
|
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
|
2018-09-06 09:48:57 +00:00
|
|
|
|
|
|
|
let(:git_blob) do
|
|
|
|
Gitlab::Git::Blob.find(
|
|
|
|
repository,
|
|
|
|
'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6',
|
|
|
|
'files/ruby/regex.rb'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
let(:blob) { Blob.new(git_blob) }
|
|
|
|
|
2019-06-04 13:38:18 +00:00
|
|
|
describe '.web_url' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:blob) { Gitlab::Graphql::Representation::TreeEntry.new(repository.tree.blobs.first, repository) }
|
|
|
|
|
|
|
|
subject { described_class.new(blob) }
|
|
|
|
|
2020-01-27 12:08:35 +00:00
|
|
|
it { expect(subject.web_url).to eq("http://localhost/#{project.full_path}/-/blob/#{blob.commit_id}/#{blob.path}") }
|
2019-06-04 13:38:18 +00:00
|
|
|
end
|
|
|
|
|
2020-07-23 15:09:28 +00:00
|
|
|
describe '#web_path' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:blob) { Gitlab::Graphql::Representation::TreeEntry.new(repository.tree.blobs.first, repository) }
|
|
|
|
|
|
|
|
subject { described_class.new(blob) }
|
|
|
|
|
|
|
|
it { expect(subject.web_path).to eq("/#{project.full_path}/-/blob/#{blob.commit_id}/#{blob.path}") }
|
|
|
|
end
|
|
|
|
|
2018-09-06 09:48:57 +00:00
|
|
|
describe '#highlight' do
|
|
|
|
subject { described_class.new(blob) }
|
|
|
|
|
|
|
|
it 'returns highlighted content' do
|
2019-08-09 00:13:09 +00:00
|
|
|
expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: nil)
|
2018-09-06 09:48:57 +00:00
|
|
|
|
|
|
|
subject.highlight
|
|
|
|
end
|
|
|
|
|
2018-09-11 04:37:44 +00:00
|
|
|
it 'returns plain content when :plain is true' do
|
2019-08-09 00:13:09 +00:00
|
|
|
expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: true, language: nil)
|
2018-09-06 09:48:57 +00:00
|
|
|
|
2018-09-11 04:37:44 +00:00
|
|
|
subject.highlight(plain: true)
|
2018-09-06 09:48:57 +00:00
|
|
|
end
|
|
|
|
|
2019-09-02 03:19:32 +00:00
|
|
|
context '"to" param is present' do
|
|
|
|
before do
|
|
|
|
allow(git_blob)
|
|
|
|
.to receive(:data)
|
|
|
|
.and_return("line one\nline two\nline 3")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns limited highlighted content' do
|
|
|
|
expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', "line one\n", plain: nil, language: nil)
|
|
|
|
|
|
|
|
subject.highlight(to: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-06 09:48:57 +00:00
|
|
|
context 'gitlab-language contains a match' do
|
|
|
|
before do
|
|
|
|
allow(blob).to receive(:language_from_gitattributes).and_return('ruby')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes language to inner call' do
|
2019-08-09 00:13:09 +00:00
|
|
|
expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: 'ruby')
|
2018-09-06 09:48:57 +00:00
|
|
|
|
|
|
|
subject.highlight
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|