2016-03-23 06:24:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Badge::Build do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:sha) { project.commit.sha }
|
2016-04-01 07:03:14 -04:00
|
|
|
let(:branch) { 'master' }
|
|
|
|
let(:badge) { described_class.new(project, branch) }
|
2016-03-23 06:24:18 -04:00
|
|
|
|
|
|
|
describe '#type' do
|
|
|
|
subject { badge.type }
|
|
|
|
it { is_expected.to eq 'image/svg+xml' }
|
|
|
|
end
|
|
|
|
|
2016-07-28 08:35:02 -04:00
|
|
|
describe '#metadata' do
|
|
|
|
it 'returns badge metadata' do
|
|
|
|
expect(badge.metadata.image_url)
|
|
|
|
.to include 'badges/master/build.svg'
|
2016-04-01 07:03:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-29 02:55:49 -04:00
|
|
|
context 'build exists' do
|
2016-06-01 07:11:28 -04:00
|
|
|
let!(:build) { create_build(project, sha, branch) }
|
2016-03-29 02:55:49 -04:00
|
|
|
|
|
|
|
context 'build success' do
|
|
|
|
before { build.success! }
|
|
|
|
|
2016-07-28 08:58:53 -04:00
|
|
|
describe '#status' do
|
|
|
|
it 'is successful' do
|
|
|
|
expect(badge.status).to eq 'success'
|
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#data' do
|
|
|
|
let(:data) { badge.data }
|
|
|
|
|
2016-04-11 10:55:40 -04:00
|
|
|
it 'contains information about success' do
|
2016-03-29 02:55:49 -04:00
|
|
|
expect(status_node(data, 'success')).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'build failed' do
|
|
|
|
before { build.drop! }
|
2016-03-23 06:24:18 -04:00
|
|
|
|
2016-07-28 08:58:53 -04:00
|
|
|
describe '#status' do
|
|
|
|
it 'failed' do
|
|
|
|
expect(badge.status).to eq 'failed'
|
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#data' do
|
|
|
|
let(:data) { badge.data }
|
|
|
|
|
2016-04-11 10:55:40 -04:00
|
|
|
it 'contains information about failure' do
|
2016-03-29 02:55:49 -04:00
|
|
|
expect(status_node(data, 'failed')).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'build does not exist' do
|
2016-07-28 08:58:53 -04:00
|
|
|
describe '#status' do
|
|
|
|
it 'is unknown' do
|
|
|
|
expect(badge.status).to eq 'unknown'
|
|
|
|
end
|
2016-03-23 06:24:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#data' do
|
|
|
|
let(:data) { badge.data }
|
|
|
|
|
2016-03-29 02:55:49 -04:00
|
|
|
it 'contains infromation about unknown build' do
|
|
|
|
expect(status_node(data, 'unknown')).to be_truthy
|
2016-03-23 06:24:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-29 02:55:49 -04:00
|
|
|
|
2016-06-01 07:11:28 -04:00
|
|
|
context 'when outdated pipeline for given ref exists' do
|
|
|
|
before do
|
|
|
|
build = create_build(project, sha, branch)
|
|
|
|
build.success!
|
|
|
|
|
|
|
|
old_build = create_build(project, '11eeffdd', branch)
|
|
|
|
old_build.drop!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not take outdated pipeline into account' do
|
2016-07-28 08:58:53 -04:00
|
|
|
expect(badge.status).to eq 'success'
|
2016-06-01 07:11:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_build(project, sha, branch)
|
2016-06-06 14:24:13 -04:00
|
|
|
pipeline = create(:ci_pipeline, project: project,
|
2016-06-07 04:25:57 -04:00
|
|
|
sha: sha,
|
|
|
|
ref: branch)
|
2016-06-01 07:11:28 -04:00
|
|
|
|
2016-07-19 07:23:14 -04:00
|
|
|
create(:ci_build, pipeline: pipeline, stage: 'notify')
|
2016-06-01 07:11:28 -04:00
|
|
|
end
|
|
|
|
|
2016-03-29 02:55:49 -04:00
|
|
|
def status_node(data, status)
|
|
|
|
xml = Nokogiri::XML.parse(data)
|
|
|
|
xml.at(%Q{text:contains("#{status}")})
|
|
|
|
end
|
2016-03-23 06:24:18 -04:00
|
|
|
end
|