b8c7bef5c0
Makes it clear this is only used in dropdowns, instead of cluttering up Project class. Since we only care about branch names, it is also possible to refactor out a lot of the set/reject logic. A benchmark on Array/Set subtraction favoured using Arrays. This was with 5000 ‘branches’ and 2000 ‘protections’ to ensure a similar comparison to the commit which introduced using Set for intersection. Comparison: array subtraction: 485.8 i/s set subtraction: 128.7 i/s - 3.78x slower
24 lines
791 B
Ruby
24 lines
791 B
Ruby
require 'spec_helper'
|
|
|
|
describe ProtectableDropdown, models: true do
|
|
let(:project) { create(:project, :repository) }
|
|
let(:subject) { described_class.new(project, :branches) }
|
|
|
|
describe '#protectable_ref_names' do
|
|
before do
|
|
project.protected_branches.create(name: 'master')
|
|
end
|
|
|
|
it { expect(subject.protectable_ref_names).to include('feature') }
|
|
it { expect(subject.protectable_ref_names).not_to include('master') }
|
|
|
|
it "includes branches matching a protected branch wildcard" do
|
|
expect(subject.protectable_ref_names).to include('feature')
|
|
|
|
create(:protected_branch, name: 'feat*', project: project)
|
|
|
|
subject = described_class.new(project.reload, :branches)
|
|
expect(subject.protectable_ref_names).to include('feature')
|
|
end
|
|
end
|
|
end
|