2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-20 19:03:20 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe Tree do
|
2022-07-12 14:08:46 -04:00
|
|
|
let_it_be(:repository) { create(:project, :repository).repository }
|
|
|
|
|
2016-01-20 19:03:20 -05:00
|
|
|
let(:sha) { repository.root_ref }
|
|
|
|
|
2021-07-29 05:08:46 -04:00
|
|
|
subject(:tree) { described_class.new(repository, '54fcc214') }
|
2016-01-20 19:03:20 -05:00
|
|
|
|
|
|
|
describe '#readme' do
|
2020-05-19 11:08:04 -04:00
|
|
|
before do
|
|
|
|
stub_const('FakeBlob', Class.new)
|
|
|
|
FakeBlob.class_eval do
|
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
|
|
|
|
def readme?
|
|
|
|
name =~ /^readme/i
|
|
|
|
end
|
2016-01-20 19:03:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when repository does not contains a README file' do
|
|
|
|
files = [FakeBlob.new('file'), FakeBlob.new('license'), FakeBlob.new('copying')]
|
|
|
|
expect(subject).to receive(:blobs).and_return(files)
|
|
|
|
|
|
|
|
expect(subject.readme).to eq nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when repository does not contains a previewable README file' do
|
|
|
|
files = [FakeBlob.new('file'), FakeBlob.new('README.pages'), FakeBlob.new('README.png')]
|
|
|
|
expect(subject).to receive(:blobs).and_return(files)
|
|
|
|
|
|
|
|
expect(subject.readme).to eq nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns README when repository contains a previewable README file' do
|
|
|
|
files = [FakeBlob.new('README.png'), FakeBlob.new('README'), FakeBlob.new('file')]
|
|
|
|
expect(subject).to receive(:blobs).and_return(files)
|
|
|
|
|
|
|
|
expect(subject.readme.name).to eq 'README'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns first previewable README when repository contains more than one' do
|
|
|
|
files = [FakeBlob.new('file'), FakeBlob.new('README.md'), FakeBlob.new('README.asciidoc')]
|
|
|
|
expect(subject).to receive(:blobs).and_return(files)
|
|
|
|
|
|
|
|
expect(subject.readme.name).to eq 'README.md'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns first plain text README when repository contains more than one' do
|
|
|
|
files = [FakeBlob.new('file'), FakeBlob.new('README'), FakeBlob.new('README.txt')]
|
|
|
|
expect(subject).to receive(:blobs).and_return(files)
|
|
|
|
|
|
|
|
expect(subject.readme.name).to eq 'README'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'prioritizes previewable README file over one in plain text' do
|
|
|
|
files = [FakeBlob.new('file'), FakeBlob.new('README'), FakeBlob.new('README.md')]
|
|
|
|
expect(subject).to receive(:blobs).and_return(files)
|
|
|
|
|
|
|
|
expect(subject.readme.name).to eq 'README.md'
|
|
|
|
end
|
|
|
|
end
|
2021-07-29 05:08:46 -04:00
|
|
|
|
|
|
|
describe '#cursor' do
|
|
|
|
subject { tree.cursor }
|
|
|
|
|
|
|
|
it { is_expected.to be_an_instance_of(Gitaly::PaginationCursor) }
|
|
|
|
end
|
2016-01-20 19:03:20 -05:00
|
|
|
end
|