2018-05-07 12:22:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-25 07:43:11 -04:00
|
|
|
require 'spec_helper'
|
2018-05-07 12:22:07 -04:00
|
|
|
|
|
|
|
describe Gitlab::Ci::Pipeline::Preloader do
|
2018-05-22 07:55:05 -04:00
|
|
|
let(:stage) { double(:stage) }
|
|
|
|
let(:commit) { double(:commit) }
|
2018-05-07 12:22:07 -04:00
|
|
|
|
2018-05-22 07:55:05 -04:00
|
|
|
let(:pipeline) do
|
|
|
|
double(:pipeline, commit: commit, stages: [stage])
|
|
|
|
end
|
2018-05-07 12:22:07 -04:00
|
|
|
|
2018-05-23 04:22:28 -04:00
|
|
|
describe '.preload!' do
|
2018-05-25 07:43:11 -04:00
|
|
|
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
|
|
|
|
|
2018-05-22 07:55:05 -04:00
|
|
|
it 'preloads commit authors and number of warnings' do
|
|
|
|
expect(commit).to receive(:lazy_author)
|
|
|
|
expect(pipeline).to receive(:number_of_warnings)
|
|
|
|
expect(stage).to receive(:number_of_warnings)
|
2018-05-07 12:22:07 -04:00
|
|
|
|
2018-05-23 04:22:28 -04:00
|
|
|
described_class.preload!([pipeline])
|
2018-05-07 12:22:07 -04:00
|
|
|
end
|
2018-05-23 07:29:21 -04:00
|
|
|
|
|
|
|
it 'returns original collection' do
|
|
|
|
allow(commit).to receive(:lazy_author)
|
|
|
|
allow(pipeline).to receive(:number_of_warnings)
|
|
|
|
allow(stage).to receive(:number_of_warnings)
|
|
|
|
|
|
|
|
pipelines = [pipeline, pipeline]
|
|
|
|
|
|
|
|
expect(described_class.preload!(pipelines)).to eq pipelines
|
|
|
|
end
|
2018-05-07 12:22:07 -04:00
|
|
|
end
|
|
|
|
end
|