debian-mirror-gitlab/spec/workers/update_external_pull_requests_worker_spec.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe UpdateExternalPullRequestsWorker do
2019-12-04 20:38:33 +05:30
describe '#perform' do
2020-04-08 14:13:33 +05:30
let_it_be(:project) { create(:project, import_source: 'tanuki/repository') }
let_it_be(:user) { create(:user) }
2019-12-04 20:38:33 +05:30
let(:worker) { described_class.new }
before do
create(:external_pull_request,
project: project,
source_repository: project.import_source,
target_repository: project.import_source,
source_branch: 'feature-1',
target_branch: 'master')
create(:external_pull_request,
project: project,
source_repository: project.import_source,
target_repository: project.import_source,
source_branch: 'feature-1',
target_branch: 'develop')
end
subject { worker.perform(project.id, user.id, ref) }
context 'when ref is a branch' do
let(:ref) { 'refs/heads/feature-1' }
2020-04-22 19:07:51 +05:30
let(:create_pipeline_service) { instance_double(Ci::ExternalPullRequests::CreatePipelineService) }
2019-12-04 20:38:33 +05:30
it 'runs CreatePipelineService for each pull request matching the source branch and repository' do
2020-04-22 19:07:51 +05:30
expect(Ci::ExternalPullRequests::CreatePipelineService)
2019-12-04 20:38:33 +05:30
.to receive(:new)
.and_return(create_pipeline_service)
.twice
expect(create_pipeline_service).to receive(:execute).twice
subject
end
end
context 'when ref is not a branch' do
let(:ref) { 'refs/tags/v1.2.3' }
it 'does nothing' do
2020-04-22 19:07:51 +05:30
expect(Ci::ExternalPullRequests::CreatePipelineService).not_to receive(:new)
2019-12-04 20:38:33 +05:30
subject
end
end
end
end