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

gitlab_ci_yml_spec.rb « blob_viewer « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 803614d90a501a48096c7b8586c2def11b3cb9d2 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BlobViewer::GitlabCiYml 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 { described_class.new(blob) }

  describe '#validation_message' do
    it 'calls prepare! on the viewer' do
      expect(subject).to receive(:prepare!)

      subject.validation_message(project: project, sha: sha, user: user)
    end

    context 'when the configuration is valid' do
      it 'returns nil' do
        expect(subject.validation_message(project: project, sha: sha, user: user)).to be_nil
      end
    end

    context 'when the configuration is invalid' do
      let(:data) { 'oof' }

      it 'returns the error message' do
        expect(subject.validation_message(project: project, sha: sha, user: user)).to eq('Invalid configuration format')
      end
    end
  end
end