diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-04-29 23:21:06 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-04-29 23:21:06 +0300 |
commit | e28d1fa3cc2e8c2f696f6740c8a8441100542470 (patch) | |
tree | e353ecddd503675ed9154331d105e423d1f43ce8 /spec | |
parent | 47698071d9685b763b2ba87f99b62c36d7735299 (diff) |
Use a query in Project#protected_branch?
This changes Project#protected_branch? to use a query to check if a
branch is protected, instead of loading all ProtectedBranch records into
memory just to check if the list of names includes a given branch name.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_spec.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e33c7d62ff4..5b1cf71337e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -798,4 +798,18 @@ describe Project, models: true do end end end + + describe '#protected_branch?' do + let(:project) { create(:empty_project) } + + it 'returns true when a branch is a protected branch' do + project.protected_branches.create!(name: 'foo') + + expect(project.protected_branch?('foo')).to eq(true) + end + + it 'returns false when a branch is not a protected branch' do + expect(project.protected_branch?('foo')).to eq(false) + end + end end |