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 Permalink 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'
2023-05-27 22:25:52 +05:30
RSpec.describe Issues::RelatedBranchesService, feature_category: :team_planning 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
2023-04-23 21:23:45 +05:30
subject { described_class.new(container: 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
2023-04-23 21:23:45 +05:30
.new(container: 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