diff options
Diffstat (limited to 'spec/models/protected_branch_spec.rb')
-rw-r--r-- | spec/models/protected_branch_spec.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index c99c92e6c19..0a75250b68c 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -13,6 +13,30 @@ RSpec.describe ProtectedBranch, feature_category: :source_code_management do describe 'Validation' do it { is_expected.to validate_presence_of(:name) } + context 'uniqueness' do + let(:protected_branch) { build(:protected_branch) } + + subject { protected_branch } + + it { is_expected.to validate_uniqueness_of(:name).scoped_to([:project_id, :namespace_id]) } + + context 'when the protected_branch was saved previously' do + before do + protected_branch.save! + end + + it { is_expected.not_to validate_uniqueness_of(:name) } + + context 'and name is changed' do + before do + protected_branch.name = "#{protected_branch.name} + something else" + end + + it { is_expected.to validate_uniqueness_of(:name).scoped_to([:project_id, :namespace_id]) } + end + end + end + describe '#validate_either_project_or_top_group' do context 'when protected branch does not have project or group association' do it 'validate failed' do @@ -311,6 +335,7 @@ RSpec.describe ProtectedBranch, feature_category: :source_code_management do context "when feature flag disabled" do before do stub_feature_flags(group_protected_branches: false) + stub_feature_flags(allow_protected_branches_for_group: false) end let(:subject_branch) { create(:protected_branch, allow_force_push: allow_force_push, name: "foo") } @@ -350,6 +375,7 @@ RSpec.describe ProtectedBranch, feature_category: :source_code_management do with_them do before do stub_feature_flags(group_protected_branches: true) + stub_feature_flags(allow_protected_branches_for_group: true) unless group_level_value.nil? create(:protected_branch, allow_force_push: group_level_value, name: "foo", project: nil, group: group) @@ -403,6 +429,7 @@ RSpec.describe ProtectedBranch, feature_category: :source_code_management do context 'when feature flag enabled' do before do stub_feature_flags(group_protected_branches: true) + stub_feature_flags(allow_protected_branches_for_group: true) end it 'call `all_protected_branches`' do @@ -415,6 +442,7 @@ RSpec.describe ProtectedBranch, feature_category: :source_code_management do context 'when feature flag disabled' do before do stub_feature_flags(group_protected_branches: false) + stub_feature_flags(allow_protected_branches_for_group: false) end it 'call `protected_branches`' do |