debian-mirror-gitlab/spec/services/ci/update_pending_build_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.9 KiB
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::UpdatePendingBuildService do
2021-11-18 22:05:49 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, namespace: group) }
let_it_be_with_reload(:pending_build_1) { create(:ci_pending_build, project: project, instance_runners_enabled: false) }
let_it_be_with_reload(:pending_build_2) { create(:ci_pending_build, project: project, instance_runners_enabled: true) }
let_it_be(:update_params) { { instance_runners_enabled: true } }
let(:service) { described_class.new(model, update_params) }
2021-11-11 11:23:49 +05:30
2021-11-18 22:05:49 +05:30
describe '#execute' do
subject(:update_pending_builds) { service.execute }
2021-11-11 11:23:49 +05:30
context 'validations' do
context 'when model is invalid' do
let(:model) { pending_build_1 }
it 'raises an error' do
2021-11-18 22:05:49 +05:30
expect { update_pending_builds }.to raise_error(described_class::InvalidModelError)
2021-11-11 11:23:49 +05:30
end
end
context 'when params is invalid' do
let(:model) { group }
let(:update_params) { { minutes_exceeded: true } }
it 'raises an error' do
2021-11-18 22:05:49 +05:30
expect { update_pending_builds }.to raise_error(described_class::InvalidParamsError)
2021-11-11 11:23:49 +05:30
end
end
end
context 'when model is a group with pending builds' do
let(:model) { group }
it 'updates all pending builds', :aggregate_failures do
2021-11-18 22:05:49 +05:30
update_pending_builds
2021-11-11 11:23:49 +05:30
2021-11-18 22:05:49 +05:30
expect(pending_build_1.instance_runners_enabled).to be_truthy
expect(pending_build_2.instance_runners_enabled).to be_truthy
2021-11-11 11:23:49 +05:30
end
end
context 'when model is a project with pending builds' do
let(:model) { project }
it 'updates all pending builds', :aggregate_failures do
2021-11-18 22:05:49 +05:30
update_pending_builds
2021-11-11 11:23:49 +05:30
2021-11-18 22:05:49 +05:30
expect(pending_build_1.instance_runners_enabled).to be_truthy
expect(pending_build_2.instance_runners_enabled).to be_truthy
2021-11-11 11:23:49 +05:30
end
end
end
end