blob: 36b75e5338aaaf1019b01f410428cddc702b266b (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BlobViewer::GitlabCiYml, feature_category: :source_code_management do
include FakeBlobHelpers
include RepoHelpers
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let(:data) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
let(:blob) { fake_blob(path: '.gitlab-ci.yml', data: data) }
let(:sha) { sample_commit.id }
subject(:blob_viewer) { described_class.new(blob) }
describe '#validation_message' do
subject(:validation_message) { blob_viewer.validation_message(project: project, sha: sha, user: user) }
it 'calls prepare! on the viewer' do
expect(blob_viewer).to receive(:prepare!)
validation_message
end
context 'when the configuration is valid' do
it 'returns nil' do
expect(validation_message).to be_nil
end
end
context 'when the configuration is invalid' do
let(:data) { 'oof' }
it 'returns the error message' do
expect(validation_message).to eq('Invalid configuration format')
end
end
context 'when the sha is from a fork' do
include_context 'when a project repository contains a forked commit'
let(:sha) { forked_commit_sha }
context 'when a project ref contains the sha' do
before do
mock_branch_contains_forked_commit_sha
end
it 'returns nil' do
expect(validation_message).to be_nil
end
end
context 'when a project ref does not contain the sha' do
it 'returns an error' do
expect(validation_message).to match(/Could not validate configuration/)
end
end
end
end
end
|