Commit d442eca8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'weimeng-prevent-approval-group-name-collision' into 'master'

Prevent project's approval rules having same name

See merge request gitlab-org/gitlab-ee!16216
parents f61bc8a4 7b61f8b8
...@@ -13,6 +13,8 @@ class ApprovalProjectRule < ApplicationRecord ...@@ -13,6 +13,8 @@ class ApprovalProjectRule < ApplicationRecord
alias_method :code_owner, :code_owner? alias_method :code_owner, :code_owner?
validates :name, uniqueness: { scope: :project_id }
def source_rule def source_rule
nil nil
end end
......
---
title: Prevent project's approval rules having same name
merge_request: 16216
author:
type: fixed
...@@ -31,7 +31,7 @@ FactoryBot.define do ...@@ -31,7 +31,7 @@ FactoryBot.define do
factory :approval_project_rule do factory :approval_project_rule do
project project
name ApprovalRuleLike::DEFAULT_NAME sequence(:name) { |n| "#{ApprovalRuleLike::DEFAULT_NAME}-#{n}" }
rule_type :regular rule_type :regular
trait :requires_approval do trait :requires_approval do
......
...@@ -5,6 +5,10 @@ require 'spec_helper' ...@@ -5,6 +5,10 @@ require 'spec_helper'
describe ApprovalProjectRule do describe ApprovalProjectRule do
subject { create(:approval_project_rule) } subject { create(:approval_project_rule) }
describe 'validations' do
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
end
describe '.regular' do describe '.regular' do
it 'returns non-report_approver records' do it 'returns non-report_approver records' do
rules = create_list(:approval_project_rule, 2) rules = create_list(:approval_project_rule, 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment