Skip to content
代码片段 群组 项目
提交 e7a8aaf1 编辑于 作者: Song Huang's avatar Song Huang 提交者: Max Woolf
浏览文件

Add groups support to ProtectedBranchesFinder

上级 4d23d9d4
No related branches found
No related tags found
1 合并请求!1355Draft: Reset password by phone with geetest captcha
......@@ -11,15 +11,21 @@
class ProtectedBranchesFinder
LIMIT = 100
attr_accessor :project, :params
attr_accessor :project_or_group, :params
def initialize(project, params = {})
@project = project
def initialize(project_or_group, params = {})
@project_or_group = project_or_group
@params = params
end
def execute
protected_branches = project.limited_protected_branches(LIMIT)
protected_branches = if project_or_group.is_a?(Group)
project_or_group.protected_branches
else
project_or_group.all_protected_branches
end
protected_branches = protected_branches.limit(LIMIT)
by_name(protected_branches)
end
......
......@@ -3,35 +3,57 @@
require 'spec_helper'
RSpec.describe ProtectedBranchesFinder do
let(:project) { create(:project) }
let!(:protected_branch) { create(:protected_branch, project: project) }
let!(:another_protected_branch) { create(:protected_branch, project: project) }
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) }
let!(:other_protected_branch) { create(:protected_branch) }
let(:params) { {} }
subject { described_class.new(entity, params).execute }
describe '#execute' do
subject { described_class.new(project, params).execute }
shared_examples 'execute by entity' do
it 'returns all protected branches of project by default' do
expect(subject).to match_array(expected_branches)
end
it 'returns all protected branches of project by default' do
expect(subject).to match_array([protected_branch, another_protected_branch])
end
context 'when search param is present' do
let(:params) { { search: group_protected_branch.name } }
context 'when search param is present' do
let(:params) { { search: protected_branch.name } }
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
it 'filters by search param' do
expect(subject).to eq([protected_branch])
it 'returns limited protected branches of project' do
expect(subject.count).to eq(1)
end
end
end
context 'when there are more protected branches than the limit' do
before do
stub_const("#{described_class}::LIMIT", 1)
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
]
end
end
it 'returns limited protected branches of project' do
expect(subject.count).to eq(1)
end
it_behaves_like 'execute by entity' do
let(:entity) { group }
let(:expected_branches) { [group_protected_branch, another_group_protected_branch] }
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册