summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-04-03 17:10:58 +0100
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-04-03 17:19:53 +0100
commitb8c7bef5c092152ea85d1840e587cfc04293e1d7 (patch)
tree51338a1599fa24d4e42c4eb7b6c02ac91555a73c /spec
parent65f3d5062f081d8f8ebf727a3408650d90ec9711 (diff)
downloadgitlab-ce-b8c7bef5c092152ea85d1840e587cfc04293e1d7.tar.gz
Extracted ProtectableDropdown to clean up Project#open_branches
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
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_spec.rb19
-rw-r--r--spec/models/protectable_dropdown_spec.rb24
2 files changed, 24 insertions, 19 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index f68631ebe06..cc06949974e 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -702,25 +702,6 @@ describe Project, models: true do
end
end
- describe '#open_branches' do
- let(:project) { create(:project, :repository) }
-
- before do
- project.protected_branches.create(name: 'master')
- end
-
- it { expect(project.open_branches.map(&:name)).to include('feature') }
- it { expect(project.open_branches.map(&:name)).not_to include('master') }
-
- it "includes branches matching a protected branch wildcard" do
- expect(project.open_branches.map(&:name)).to include('feature')
-
- create(:protected_branch, name: 'feat*', project: project)
-
- expect(Project.find(project.id).open_branches.map(&:name)).to include('feature')
- end
- end
-
describe '#star_count' do
it 'counts stars from multiple users' do
user1 = create :user
diff --git a/spec/models/protectable_dropdown_spec.rb b/spec/models/protectable_dropdown_spec.rb
new file mode 100644
index 00000000000..7f8ef7195e5
--- /dev/null
+++ b/spec/models/protectable_dropdown_spec.rb
@@ -0,0 +1,24 @@
+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