Commit 3b0786f2 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'fix-multiple-blocks-on-same-mr' into 'master'

Allow MRs to participate in multiple blocks

See merge request gitlab-org/gitlab-ee!12855
parents 898001ce 4837ffea
......@@ -6,7 +6,7 @@ class MergeRequestBlock < ApplicationRecord
validates_presence_of :blocking_merge_request
validates_presence_of :blocked_merge_request
validates_uniqueness_of [:blocking_merge_request, :blocked_merge_request]
validates_uniqueness_of :blocked_merge_request, scope: :blocking_merge_request
validate :check_block_constraints
......
......@@ -11,6 +11,10 @@ describe MergeRequestBlock do
describe 'validations' do
subject(:block) { create(:merge_request_block) }
let(:blocking_mr) { block.blocking_merge_request }
let(:blocked_mr) { block.blocked_merge_request }
let(:another_mr) { create(:merge_request) }
it { is_expected.to validate_presence_of(:blocking_merge_request) }
it { is_expected.to validate_presence_of(:blocked_merge_request) }
......@@ -20,6 +24,24 @@ describe MergeRequestBlock do
expect(block).not_to be_valid
end
it 'allows an MR to block multiple MRs' do
another_block = described_class.new(
blocking_merge_request: blocking_mr,
blocked_merge_request: another_mr
)
expect(another_block).to be_valid
end
it 'allows an MR to be blocked by multiple MRs' do
another_block = described_class.new(
blocking_merge_request: another_mr,
blocked_merge_request: blocked_mr
)
expect(another_block).to be_valid
end
it 'forbids duplicate blocks' do
new_block = described_class.new(block.attributes)
......
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