debian-mirror-gitlab/spec/lib/gitlab/badge/pipeline/status_spec.rb

100 lines
2.2 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Gitlab::Badge::Pipeline::Status do
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2016-09-13 17:45:13 +05:30
let(:sha) { project.commit.sha }
let(:branch) { 'master' }
let(:badge) { described_class.new(project, branch) }
describe '#entity' do
2017-09-10 17:25:29 +05:30
it 'always says pipeline' do
expect(badge.entity).to eq 'pipeline'
2016-09-13 17:45:13 +05:30
end
end
describe '#template' do
it 'returns badge template' do
2017-09-10 17:25:29 +05:30
expect(badge.template.key_text).to eq 'pipeline'
2016-09-13 17:45:13 +05:30
end
end
describe '#metadata' do
it 'returns badge metadata' do
2017-09-10 17:25:29 +05:30
expect(badge.metadata.image_url).to include 'badges/master/pipeline.svg'
2016-09-13 17:45:13 +05:30
end
end
2017-09-10 17:25:29 +05:30
context 'pipeline exists' do
let!(:pipeline) { create_pipeline(project, sha, branch) }
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
context 'pipeline success' do
before do
pipeline.success!
end
2016-09-13 17:45:13 +05:30
describe '#status' do
it 'is successful' do
expect(badge.status).to eq 'success'
end
end
end
2017-09-10 17:25:29 +05:30
context 'pipeline failed' do
before do
pipeline.drop!
end
2016-09-13 17:45:13 +05:30
describe '#status' do
it 'failed' do
expect(badge.status).to eq 'failed'
end
end
end
context 'when outdated pipeline for given ref exists' do
before do
2017-09-10 17:25:29 +05:30
pipeline.success!
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
old_pipeline = create_pipeline(project, '11eeffdd', branch)
old_pipeline.drop!
2016-09-13 17:45:13 +05:30
end
it 'does not take outdated pipeline into account' do
expect(badge.status).to eq 'success'
end
end
context 'when multiple pipelines exist for given sha' do
before do
2017-09-10 17:25:29 +05:30
pipeline.drop!
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
new_pipeline = create_pipeline(project, sha, branch)
new_pipeline.success!
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
it 'does not take outdated pipeline into account' do
expect(badge.status).to eq 'success'
2016-09-13 17:45:13 +05:30
end
end
end
context 'build does not exist' do
describe '#status' do
it 'is unknown' do
expect(badge.status).to eq 'unknown'
end
end
end
2017-09-10 17:25:29 +05:30
def create_pipeline(project, sha, branch)
2016-09-13 17:45:13 +05:30
pipeline = create(:ci_empty_pipeline,
project: project,
sha: sha,
ref: branch)
create(:ci_build, pipeline: pipeline, stage: 'notify')
end
end