debian-mirror-gitlab/spec/lib/gitlab/ci/pipeline/preloader_spec.rb

58 lines
1.9 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Pipeline::Preloader do
2018-11-08 19:23:39 +05:30
let(:stage) { double(:stage) }
let(:commit) { double(:commit) }
2021-09-04 01:27:46 +05:30
let(:scheduled_action) { double(:scheduled_action) }
let(:manual_action) { double(:manual_action) }
2018-11-08 19:23:39 +05:30
let(:pipeline) do
2021-09-04 01:27:46 +05:30
double(:pipeline, commit: commit, stages: [stage], scheduled_actions: [scheduled_action], manual_actions: [manual_action])
2018-11-08 19:23:39 +05:30
end
describe '.preload!' do
context 'when preloading multiple commits' do
let(:project) { create(:project, :repository) }
it 'preloads all commits once' do
expect(Commit).to receive(:decorate).once.and_call_original
pipelines = [build_pipeline(ref: 'HEAD'),
build_pipeline(ref: 'HEAD~1')]
described_class.preload!(pipelines)
end
def build_pipeline(ref:)
build_stubbed(:ci_pipeline, project: project, sha: project.commit(ref).id)
end
end
2020-07-28 23:09:34 +05:30
it 'preloads commit authors, number of warnings and ref commits' do
2018-11-08 19:23:39 +05:30
expect(commit).to receive(:lazy_author)
2020-07-28 23:09:34 +05:30
expect(pipeline).to receive(:lazy_ref_commit)
2018-11-08 19:23:39 +05:30
expect(pipeline).to receive(:number_of_warnings)
expect(stage).to receive(:number_of_warnings)
2021-09-04 01:27:46 +05:30
expect(scheduled_action).to receive(:persisted_environment)
expect(manual_action).to receive(:persisted_environment)
2018-11-08 19:23:39 +05:30
described_class.preload!([pipeline])
end
it 'returns original collection' do
allow(commit).to receive(:lazy_author)
2020-07-28 23:09:34 +05:30
allow(pipeline).to receive(:lazy_ref_commit)
2018-11-08 19:23:39 +05:30
allow(pipeline).to receive(:number_of_warnings)
allow(stage).to receive(:number_of_warnings)
2021-09-04 01:27:46 +05:30
allow(scheduled_action).to receive(:persisted_environment)
allow(manual_action).to receive(:persisted_environment)
2018-11-08 19:23:39 +05:30
pipelines = [pipeline, pipeline]
expect(described_class.preload!(pipelines)).to eq pipelines
end
end
end