2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-11 13:22:35 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe Ci::ProcessPipelineService do
|
2016-08-11 13:22:35 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2017-02-13 12:19:23 +00:00
|
|
|
|
|
|
|
let(:pipeline) do
|
|
|
|
create(:ci_empty_pipeline, ref: 'master', project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-02-28 02:56:18 +00:00
|
|
|
stub_ci_pipeline_to_return_yaml_file
|
|
|
|
|
2017-07-18 14:32:34 +00:00
|
|
|
stub_not_protect_default_branch
|
|
|
|
|
|
|
|
project.add_developer(user)
|
2017-02-13 12:19:23 +00:00
|
|
|
end
|
2016-08-11 13:22:35 +00:00
|
|
|
|
2017-04-16 11:14:39 +00:00
|
|
|
context 'updates a list of retried builds' do
|
|
|
|
subject { described_class.retried.order(:id) }
|
|
|
|
|
|
|
|
let!(:build_retried) { create_build('build') }
|
|
|
|
let!(:build) { create_build('build') }
|
|
|
|
let!(:test) { create_build('test') }
|
|
|
|
|
|
|
|
it 'returns unique statuses' do
|
|
|
|
process_pipeline
|
|
|
|
|
|
|
|
expect(all_builds.latest).to contain_exactly(build, test)
|
|
|
|
expect(all_builds.retried).to contain_exactly(build_retried)
|
|
|
|
end
|
|
|
|
end
|
2016-11-25 09:44:13 +00:00
|
|
|
|
2017-03-03 11:51:23 +00:00
|
|
|
def process_pipeline
|
2019-11-19 12:06:00 +00:00
|
|
|
described_class.new(pipeline).execute
|
2017-03-03 11:51:23 +00:00
|
|
|
end
|
|
|
|
|
2017-03-02 14:21:00 +00:00
|
|
|
def create_build(name, **opts)
|
|
|
|
create(:ci_build, :created, pipeline: pipeline, name: name, **opts)
|
2016-11-25 09:44:13 +00:00
|
|
|
end
|
2018-09-27 07:10:55 +00:00
|
|
|
|
2020-01-15 09:08:50 +00:00
|
|
|
def all_builds
|
|
|
|
pipeline.builds.order(:stage_idx, :id)
|
2018-09-27 07:10:55 +00:00
|
|
|
end
|
2016-08-11 13:22:35 +00:00
|
|
|
end
|