2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe ProtectedBranchesFinder do
|
2023-04-23 21:23:45 +05:30
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
|
|
|
|
|
|
|
let!(:project_protected_branch) { create(:protected_branch, project: project) }
|
|
|
|
let!(:another_project_protected_branch) { create(:protected_branch, project: project) }
|
|
|
|
let!(:group_protected_branch) { create(:protected_branch, project: nil, group: group) }
|
|
|
|
let!(:another_group_protected_branch) { create(:protected_branch, project: nil, group: group) }
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:other_protected_branch) { create(:protected_branch) }
|
2023-04-23 21:23:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:params) { {} }
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
subject { described_class.new(entity, params).execute }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '#execute' do
|
2023-04-23 21:23:45 +05:30
|
|
|
shared_examples 'execute by entity' do
|
|
|
|
it 'returns all protected branches of project by default' do
|
|
|
|
expect(subject).to match_array(expected_branches)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when search param is present' do
|
|
|
|
let(:params) { { search: group_protected_branch.name } }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it 'filters by search param' do
|
|
|
|
expect(subject).to eq([group_protected_branch])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are more protected branches than the limit' do
|
|
|
|
before do
|
|
|
|
stub_const("#{described_class}::LIMIT", 1)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it 'returns limited protected branches of project' do
|
|
|
|
expect(subject.count).to eq(1)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it_behaves_like 'execute by entity' do
|
|
|
|
let(:entity) { project }
|
|
|
|
let(:expected_branches) do
|
|
|
|
[
|
|
|
|
project_protected_branch, another_project_protected_branch,
|
|
|
|
group_protected_branch, another_group_protected_branch
|
|
|
|
]
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it_behaves_like 'execute by entity' do
|
|
|
|
let(:entity) { group }
|
|
|
|
let(:expected_branches) { [group_protected_branch, another_group_protected_branch] }
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|