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

has_repository_shared_examples.rb « concerns « models « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 368ec0694fd263cbce38b3f99b3f8e6416c694a9 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# frozen_string_literal: true

RSpec.shared_examples 'model with repository' do
  describe '#commits_by' do
    let(:commits) { container.repository.commits('HEAD', limit: 3).commits }
    let(:commit_shas) { commits.map(&:id) }

    it 'retrieves several commits from the repository by oid' do
      expect(container.commits_by(oids: commit_shas)).to eq commits
    end
  end

  describe "#web_url" do
    context 'when given the only_path option' do
      subject { container.web_url(only_path: only_path) }

      context 'when only_path is false' do
        let(:only_path) { false }

        it 'returns the full web URL for this repo' do
          expect(subject).to eq("#{Gitlab.config.gitlab.url}/#{expected_web_url_path}")
        end
      end

      context 'when only_path is true' do
        let(:only_path) { true }

        it 'returns the relative web URL for this repo' do
          expect(subject).to eq("/#{expected_web_url_path}")
        end
      end

      context 'when only_path is nil' do
        let(:only_path) { nil }

        it 'returns the full web URL for this repo' do
          expect(subject).to eq("#{Gitlab.config.gitlab.url}/#{expected_web_url_path}")
        end
      end
    end

    context 'when not given the only_path option' do
      it 'returns the full web URL for this repo' do
        expect(container.web_url).to eq("#{Gitlab.config.gitlab.url}/#{expected_web_url_path}")
      end
    end
  end

  describe '#ssh_url_to_repo' do
    it 'returns container ssh address' do
      expect(container.ssh_url_to_repo).to eq container.url_to_repo
    end
  end

  describe '#http_url_to_repo' do
    subject { container.http_url_to_repo }

    context 'when a custom HTTP clone URL root is not set' do
      it 'returns the url to the repo without a username' do
        expect(subject).to eq("#{container.web_url}.git")
        expect(subject).not_to include('@')
      end
    end

    context 'when a custom HTTP clone URL root is set' do
      before do
        stub_application_setting(custom_http_clone_url_root: custom_http_clone_url_root)
      end

      context 'when custom HTTP clone URL root has a relative URL root' do
        context 'when custom HTTP clone URL root ends with a slash' do
          let(:custom_http_clone_url_root) { 'https://git.example.com:51234/mygitlab/' }

          it 'returns the url to the repo, with the root replaced with the custom one' do
            expect(subject).to eq("#{custom_http_clone_url_root}#{expected_web_url_path}.git")
          end
        end

        context 'when custom HTTP clone URL root does not end with a slash' do
          let(:custom_http_clone_url_root) { 'https://git.example.com:51234/mygitlab' }

          it 'returns the url to the repo, with the root replaced with the custom one' do
            expect(subject).to eq("#{custom_http_clone_url_root}/#{expected_web_url_path}.git")
          end
        end
      end

      context 'when custom HTTP clone URL root does not have a relative URL root' do
        context 'when custom HTTP clone URL root ends with a slash' do
          let(:custom_http_clone_url_root) { 'https://git.example.com:51234/' }

          it 'returns the url to the repo, with the root replaced with the custom one' do
            expect(subject).to eq("#{custom_http_clone_url_root}#{expected_web_url_path}.git")
          end
        end

        context 'when custom HTTP clone URL root does not end with a slash' do
          let(:custom_http_clone_url_root) { 'https://git.example.com:51234' }

          it 'returns the url to the repo, with the root replaced with the custom one' do
            expect(subject).to eq("#{custom_http_clone_url_root}/#{expected_web_url_path}.git")
          end
        end
      end
    end
  end

  describe '#repository' do
    it 'returns valid repo' do
      expect(container.repository).to be_kind_of(expected_repository_klass)
    end
  end

  describe '#storage' do
    it 'returns valid storage' do
      expect(container.storage).to be_kind_of(expected_storage_klass)
    end
  end

  describe '#full_path' do
    it 'returns valid full_path' do
      expect(container.full_path).to eq(expected_full_path)
    end
  end

  describe '#empty_repo?' do
    context 'when the repo does not exist' do
      it 'returns true' do
        expect(stubbed_container.empty_repo?).to be(true)
      end
    end

    context 'when the repo exists' do
      it { expect(container.empty_repo?).to be(false) }

      it 'returns true when repository is empty' do
        allow(container.repository).to receive(:empty?).and_return(true)

        expect(container.empty_repo?).to be(true)
      end
    end
  end

  describe '#valid_repo?' do
    it { expect(stubbed_container.valid_repo?).to be(false)}
    it { expect(container.valid_repo?).to be(true) }
  end

  describe '#repository_exists?' do
    it { expect(stubbed_container.repository_exists?).to be(false)}
    it { expect(container.repository_exists?).to be(true) }
  end

  describe '#repo_exists?' do
    it { expect(stubbed_container.repo_exists?).to be(false)}
    it { expect(container.repo_exists?).to be(true) }
  end

  describe '#root_ref' do
    let(:root_ref) { container.repository.root_ref }

    it { expect(container.root_ref?(root_ref)).to be(true) }
    it { expect(container.root_ref?('HEAD')).to be(false) }
    it { expect(container.root_ref?('foo')).to be(false) }
  end

  describe 'Respond to' do
    it { is_expected.to respond_to(:base_dir) }
    it { is_expected.to respond_to(:disk_path) }
    it { is_expected.to respond_to(:gitlab_shell) }
  end

  describe '.pick_repository_storage' do
    subject { described_class.pick_repository_storage }

    before do
      storages = {
        'default' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories'),
        'picked'  => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories')
      }
      allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
    end

    it 'picks storage from ApplicationSetting' do
      expect_next_instance_of(ApplicationSetting) do |instance|
        expect(instance).to receive(:pick_repository_storage).and_return('picked')
      end

      expect(subject).to eq('picked')
    end

    it 'picks from the latest available storage', :request_store do
      stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
      Gitlab::CurrentSettings.current_application_settings

      settings = ApplicationSetting.last
      settings.repository_storages = %w(picked)
      settings.save!

      expect(Gitlab::CurrentSettings.repository_storages).to eq(%w(default))
      expect(subject).to eq('picked')
      expect(Gitlab::CurrentSettings.repository_storages).to eq(%w(picked))
    end
  end
end