diff options
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 5c6c36e6b31..bbc929e9bd4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -764,7 +764,7 @@ class Project < ActiveRecord::Base # Check if current branch name is marked as protected in the system def protected_branch?(branch_name) - protected_branches_names.include?(branch_name) + protected_branches.where(name: branch_name).any? end def developers_can_push_to_protected_branch?(branch_name) 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 |