Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tree_spec.rb « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 302cd9e9f10616183615f7e362213749cfe3251d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Tree, feature_category: :source_code_management do
  subject(:tree) { described_class.new(repository, '54fcc214') }

  let_it_be(:repository) { create(:project, :repository).repository }

  describe '#readme' do
    subject { tree.readme }

    before do
      allow(tree).to receive(:blobs).and_return(files)
    end

    context 'when repository does not contains a README file' do
      let(:files) { [fake_blob('file'), fake_blob('license'), fake_blob('copying')] }

      it { is_expected.to be_nil }
    end

    context 'when repository does not contains a previewable README file' do
      let(:files) { [fake_blob('file'), fake_blob('README.pages'), fake_blob('README.png')] }

      it { is_expected.to be_nil }
    end

    context 'when repository contains a previewable README file' do
      let(:files) { [fake_blob('README.png'), fake_blob('README'), fake_blob('file')] }

      it { is_expected.to have_attributes(name: 'README') }
    end

    context 'when repository contains more than one README file' do
      let(:files) { [fake_blob('file'), fake_blob('README.md'), fake_blob('README.asciidoc')] }

      it 'returns first previewable README' do
        is_expected.to have_attributes(name: 'README.md')
      end

      context 'when only plain-text READMEs' do
        let(:files) { [fake_blob('file'), fake_blob('README'), fake_blob('README.txt')] }

        it 'returns first plain text README' do
          is_expected.to have_attributes(name: 'README')
        end
      end
    end

    context 'when the repository has a previewable and plain text READMEs' do
      let(:files) { [fake_blob('file'), fake_blob('README'), fake_blob('README.md')] }

      it 'prefers previewable README file' do
        is_expected.to have_attributes(name: 'README.md')
      end
    end
  end

  describe '#cursor' do
    subject { tree.cursor }

    it { is_expected.to be_an_instance_of(Gitaly::PaginationCursor) }
  end

  private

  def fake_blob(name)
    instance_double(Gitlab::Git::Blob, name: name)
  end
end