2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-08 19:50:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe BlobViewer::GitlabCiYml do
|
2017-05-08 19:50:23 -04:00
|
|
|
include FakeBlobHelpers
|
2018-09-07 16:37:37 -04:00
|
|
|
include RepoHelpers
|
2017-05-08 19:50:23 -04:00
|
|
|
|
2020-02-05 07:09:15 -05:00
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2021-04-09 05:09:10 -04:00
|
|
|
|
2017-05-08 19:50:23 -04:00
|
|
|
let(:data) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
|
|
|
|
let(:blob) { fake_blob(path: '.gitlab-ci.yml', data: data) }
|
2018-09-07 16:37:37 -04:00
|
|
|
let(:sha) { sample_commit.id }
|
2019-12-18 19:08:01 -05:00
|
|
|
|
2017-05-08 19:50:23 -04:00
|
|
|
subject { described_class.new(blob) }
|
|
|
|
|
|
|
|
describe '#validation_message' do
|
|
|
|
it 'calls prepare! on the viewer' do
|
|
|
|
expect(subject).to receive(:prepare!)
|
|
|
|
|
2018-12-01 06:39:13 -05:00
|
|
|
subject.validation_message(project: project, sha: sha, user: user)
|
2017-05-08 19:50:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the configuration is valid' do
|
|
|
|
it 'returns nil' do
|
2018-12-01 06:39:13 -05:00
|
|
|
expect(subject.validation_message(project: project, sha: sha, user: user)).to be_nil
|
2017-05-08 19:50:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the configuration is invalid' do
|
|
|
|
let(:data) { 'oof' }
|
|
|
|
|
|
|
|
it 'returns the error message' do
|
2018-12-01 06:39:13 -05:00
|
|
|
expect(subject.validation_message(project: project, sha: sha, user: user)).to eq('Invalid configuration format')
|
2017-05-08 19:50:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|