2019-08-09 09:40:45 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-26 09:08:59 +00:00
|
|
|
RSpec.describe UpdateExternalPullRequestsWorker do
|
2019-08-09 09:40:45 +00:00
|
|
|
describe '#perform' do
|
2020-02-25 03:08:49 +00:00
|
|
|
let_it_be(:project) { create(:project, import_source: 'tanuki/repository') }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2019-08-09 09:40:45 +00:00
|
|
|
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-08 12:09:42 +00:00
|
|
|
let(:create_pipeline_service) { instance_double(Ci::ExternalPullRequests::CreatePipelineService) }
|
2019-08-09 09:40:45 +00:00
|
|
|
|
|
|
|
it 'runs CreatePipelineService for each pull request matching the source branch and repository' do
|
2020-04-08 12:09:42 +00:00
|
|
|
expect(Ci::ExternalPullRequests::CreatePipelineService)
|
2019-08-09 09:40:45 +00:00
|
|
|
.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-08 12:09:42 +00:00
|
|
|
expect(Ci::ExternalPullRequests::CreatePipelineService).not_to receive(:new)
|
2019-08-09 09:40:45 +00:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|