Commit c5da4406 authored by Kerri Miller's avatar Kerri Miller

Use an Entry obj instead of Struct

parent d198605c
......@@ -130,7 +130,7 @@ module EE
rule = approval_rules.code_owner.first
rule ||= ApprovalMergeRequestRule.find_or_create_code_owner_rule(
self,
Struct.new(:pattern, :owner_line).new("Code Owner")
::Gitlab::CodeOwners::Entry.new("Code Owner", owners)
)
rule.users = owners.uniq
......
......@@ -156,17 +156,16 @@ describe ApprovalMergeRequestRule do
describe '.find_or_create_code_owner_rule' do
let!(:existing_code_owner_rule) { create(:code_owner_rule, name: '*.rb', merge_request: merge_request) }
let(:entry) { Struct.new(:pattern, :owner_line).new }
it 'finds an existing rule' do
entry.pattern = "*.rb"
entry = Gitlab::CodeOwners::Entry.new("*.rb", "@user")
expect(described_class.find_or_create_code_owner_rule(merge_request, entry))
.to eq(existing_code_owner_rule)
end
it 'creates a new rule if it does not exist' do
entry.pattern = "*.js"
entry = Gitlab::CodeOwners::Entry.new("*.js", "@user")
expect { described_class.find_or_create_code_owner_rule(merge_request, entry) }
.to change { merge_request.approval_rules.matching_pattern('*.js').count }.by(1)
......@@ -176,7 +175,7 @@ describe ApprovalMergeRequestRule do
deprecated_code_owner_rule = create(:code_owner_rule, name: '*.md', merge_request: merge_request)
deprecated_code_owner_rule.update_column(:rule_type, described_class.rule_types[:regular])
entry.pattern = "*.md"
entry = Gitlab::CodeOwners::Entry.new("*.md", "@user")
expect(described_class.find_or_create_code_owner_rule(merge_request, entry))
.to eq(deprecated_code_owner_rule)
......@@ -186,7 +185,7 @@ describe ApprovalMergeRequestRule do
expect(described_class).to receive(:code_owner).and_raise(ActiveRecord::RecordNotUnique)
allow(described_class).to receive(:code_owner).and_call_original
entry.pattern = "*.js"
entry = Gitlab::CodeOwners::Entry.new("*.js", "@user")
expect(described_class.find_or_create_code_owner_rule(merge_request, entry)).not_to be_nil
end
......
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