debian-mirror-gitlab/spec/services/issues/related_branches_service_spec.rb

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

74 lines
2.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-12-05 23:21:45 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Issues::RelatedBranchesService do
2022-08-13 15:12:31 +05:30
let_it_be(:project) { create(:project, :repository, :public, public_builds: false) }
2020-05-24 23:13:21 +05:30
let_it_be(:developer) { create(:user) }
2022-08-13 15:12:31 +05:30
let_it_be(:issue) { create(:issue, project: project) }
2021-04-29 21:17:54 +05:30
2020-05-24 23:13:21 +05:30
let(:user) { developer }
2018-12-05 23:21:45 +05:30
2022-08-13 15:12:31 +05:30
subject { described_class.new(project: project, current_user: user) }
2018-12-05 23:21:45 +05:30
2022-08-13 15:12:31 +05:30
before_all do
project.add_developer(developer)
2020-05-24 23:13:21 +05:30
end
2018-12-05 23:21:45 +05:30
describe '#execute' do
2020-05-24 23:13:21 +05:30
let(:branch_info) { subject.execute(issue) }
context 'branches are available' do
2022-08-13 15:12:31 +05:30
let_it_be(:pipeline) { create(:ci_pipeline, :success, project: project, ref: issue.to_branch_name) }
2020-05-24 23:13:21 +05:30
2022-08-13 15:12:31 +05:30
before_all do
project.repository.create_branch(issue.to_branch_name, pipeline.sha)
project.repository.create_branch("#{issue.iid}doesnt-match", project.repository.root_ref)
project.repository.create_branch("#{issue.iid}-0-stable", project.repository.root_ref)
2020-05-24 23:13:21 +05:30
2022-08-13 15:12:31 +05:30
project.repository.add_tag(developer, issue.to_branch_name, pipeline.sha)
2020-05-24 23:13:21 +05:30
end
2022-08-13 15:12:31 +05:30
context 'when user has access to pipelines' do
it 'selects relevant branches, along with pipeline status' do
expect(branch_info).to contain_exactly(
{ name: issue.to_branch_name, pipeline_status: an_instance_of(Gitlab::Ci::Status::Success) }
)
end
2020-05-24 23:13:21 +05:30
end
2022-08-13 15:12:31 +05:30
context 'when user does not have access to pipelines' do
let(:user) { create(:user) }
2020-05-24 23:13:21 +05:30
2022-08-13 15:12:31 +05:30
it 'returns branches without pipeline status' do
expect(branch_info).to contain_exactly(
{ name: issue.to_branch_name, pipeline_status: nil }
)
2020-05-24 23:13:21 +05:30
end
end
it 'excludes branches referenced in merge requests' do
merge_request = create(:merge_request, { description: "Closes #{issue.to_reference}",
source_project: issue.project,
source_branch: issue.to_branch_name })
merge_request.create_cross_references!(user)
2018-12-05 23:21:45 +05:30
2020-05-24 23:13:21 +05:30
referenced_merge_requests = Issues::ReferencedMergeRequestsService
2021-06-08 01:23:25 +05:30
.new(project: issue.project, current_user: user)
2020-05-24 23:13:21 +05:30
.referenced_merge_requests(issue)
2018-12-05 23:21:45 +05:30
2020-05-24 23:13:21 +05:30
expect(referenced_merge_requests).not_to be_empty
expect(branch_info.pluck(:name)).not_to include(merge_request.source_branch)
end
2018-12-05 23:21:45 +05:30
end
2022-08-13 15:12:31 +05:30
context 'no branches are available' do
let(:project) { create(:project, :empty_repo) }
2018-12-05 23:21:45 +05:30
2022-08-13 15:12:31 +05:30
it 'returns an empty array' do
2020-05-24 23:13:21 +05:30
expect(branch_info).to be_empty
end
2018-12-05 23:21:45 +05:30
end
end
end