debian-mirror-gitlab/spec/models/ci/group_spec.rb

124 lines
3.3 KiB
Ruby
Raw Permalink Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Ci::Group do
2020-04-22 19:07:51 +05:30
let_it_be(:project) { create(:project) }
let!(:jobs) { build_list(:ci_build, 1, :success, project: project) }
2017-08-17 22:00:37 +05:30
subject do
2020-04-22 19:07:51 +05:30
described_class.new(project, 'test', name: 'rspec', jobs: jobs)
2017-08-17 22:00:37 +05:30
end
it { is_expected.to include_module(StaticModel) }
it { is_expected.to respond_to(:stage) }
it { is_expected.to respond_to(:name) }
it { is_expected.to respond_to(:jobs) }
it { is_expected.to respond_to(:status) }
describe '#size' do
it 'returns the number of statuses in the group' do
expect(subject.size).to eq(1)
end
end
2019-12-21 20:55:43 +05:30
describe '#status' do
let(:jobs) do
[create(:ci_build, :failed)]
end
2020-10-24 23:57:45 +05:30
it 'returns a failed status' do
expect(subject.status).to eq('failed')
2019-12-21 20:55:43 +05:30
end
end
2017-08-17 22:00:37 +05:30
describe '#detailed_status' do
context 'when there is only one item in the group' do
it 'calls the status from the object itself' do
expect(jobs.first).to receive(:detailed_status)
2020-04-22 19:07:51 +05:30
subject.detailed_status(double(:user))
2017-08-17 22:00:37 +05:30
end
end
context 'when there are more than one commit status in the group' do
let(:jobs) do
[create(:ci_build, :failed),
create(:ci_build, :success)]
end
it 'fabricates a new detailed status object' do
expect(subject.detailed_status(double(:user)))
.to be_a(Gitlab::Ci::Status::Failed)
end
end
2021-03-08 18:12:59 +05:30
context 'when one of the commit statuses in the group is allowed to fail' do
let(:jobs) do
[create(:ci_build, :failed, :allowed_to_fail),
create(:ci_build, :success)]
end
it 'fabricates a new detailed status object' do
expect(subject.detailed_status(double(:user)))
.to be_a(Gitlab::Ci::Status::SuccessWarning)
end
end
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
describe '.fabricate' do
let(:pipeline) { create(:ci_empty_pipeline) }
2022-08-13 15:12:31 +05:30
let(:stage) { create(:ci_stage, pipeline: pipeline) }
2018-11-08 19:23:39 +05:30
before do
create_build(:ci_build, name: 'rspec 0 2')
create_build(:ci_build, name: 'rspec 0 1')
create_build(:ci_build, name: 'spinach 0 1')
create_build(:commit_status, name: 'aaaaa')
end
it 'returns an array of three groups' do
expect(stage.groups).to be_a Array
expect(stage.groups).to all(be_a described_class)
expect(stage.groups.size).to eq 3
end
it 'returns groups with correctly ordered statuses' do
expect(stage.groups.first.jobs.map(&:name))
.to eq ['aaaaa']
expect(stage.groups.second.jobs.map(&:name))
.to eq ['rspec 0 1', 'rspec 0 2']
expect(stage.groups.third.jobs.map(&:name))
.to eq ['spinach 0 1']
end
it 'returns groups with correct names' do
expect(stage.groups.map(&:name))
.to eq %w[aaaaa rspec spinach]
end
context 'when a name is nil on legacy pipelines' do
before do
pipeline.builds.first.update_attribute(:name, nil)
end
it 'returns an array of three groups' do
expect(stage.groups.map(&:name))
.to eq ['', 'aaaaa', 'rspec', 'spinach']
end
end
def create_build(type, status: 'success', **opts)
2023-06-20 00:43:36 +05:30
create(
type, pipeline: pipeline,
stage: stage.name,
status: status,
stage_id: stage.id,
**opts
)
2018-11-08 19:23:39 +05:30
end
end
2017-08-17 22:00:37 +05:30
end