Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1e41dc95
Commit
1e41dc95
authored
Aug 13, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respect merge request block validations
Without this change, we could create invalid MR blocks in the database
parent
2e2317a7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
45 deletions
+17
-45
ee/app/models/merge_request_block.rb
ee/app/models/merge_request_block.rb
+0
-17
ee/app/services/merge_requests/update_blocks_service.rb
ee/app/services/merge_requests/update_blocks_service.rb
+7
-3
ee/spec/models/merge_request_block_spec.rb
ee/spec/models/merge_request_block_spec.rb
+0
-25
ee/spec/services/merge_requests/update_blocks_service_spec.rb
...pec/services/merge_requests/update_blocks_service_spec.rb
+10
-0
No files found.
ee/app/models/merge_request_block.rb
View file @
1e41dc95
...
...
@@ -14,23 +14,6 @@ class MergeRequestBlock < ApplicationRecord
where
(
blocking_merge_request_id:
ids
).
includes
(
:blocking_merge_request
)
end
# Add a number of blocks at once. Pass a hash of blocking_id => blocked_id, or
# an Array of [blocking_id, blocked_id] tuples
def
self
.
bulk_insert
(
pairs
)
now
=
Time
.
current
rows
=
pairs
.
map
do
|
blocking
,
blocked
|
{
blocking_merge_request_id:
blocking
,
blocked_merge_request_id:
blocked
,
created_at:
now
,
updated_at:
now
}
end
::
Gitlab
::
Database
.
bulk_insert
(
table_name
,
rows
)
end
private
def
check_block_constraints
...
...
ee/app/services/merge_requests/update_blocks_service.rb
View file @
1e41dc95
...
...
@@ -38,9 +38,13 @@ module MergeRequests
.
with_blocking_mr_ids
(
ids_to_del
)
.
delete_all
::
MergeRequestBlock
.
bulk_insert
(
ids_to_add
.
map
{
|
blocking_id
|
[
blocking_id
,
merge_request
.
id
]
}
# If the block is invalid, silently fail to add it
ids_to_add
.
each
do
|
blocking_id
|
::
MergeRequestBlock
.
create
(
blocking_merge_request_id:
blocking_id
,
blocked_merge_request_id:
merge_request
.
id
)
end
true
end
...
...
ee/spec/models/merge_request_block_spec.rb
View file @
1e41dc95
...
...
@@ -69,31 +69,6 @@ describe MergeRequestBlock do
end
end
describe
'.bulk_insert'
do
let
(
:mrs
)
{
create_list
(
:merge_request
,
4
)
}
it
'inserts multiple blocks specified as a Hash'
do
described_class
.
bulk_insert
(
mrs
[
0
].
id
=>
mrs
[
1
].
id
,
mrs
[
2
].
id
=>
mrs
[
3
].
id
)
expect
(
described_class
.
all
).
to
contain_exactly
(
having_attributes
(
blocking_merge_request_id:
mrs
[
0
].
id
,
blocked_merge_request_id:
mrs
[
1
].
id
),
having_attributes
(
blocking_merge_request_id:
mrs
[
2
].
id
,
blocked_merge_request_id:
mrs
[
3
].
id
)
)
end
it
'inserts multiple blocks specified as an Array'
do
described_class
.
bulk_insert
([[
mrs
[
0
].
id
,
mrs
[
1
].
id
],
[
mrs
[
2
].
id
,
mrs
[
3
].
id
]])
expect
(
described_class
.
all
).
to
contain_exactly
(
having_attributes
(
blocking_merge_request_id:
mrs
[
0
].
id
,
blocked_merge_request_id:
mrs
[
1
].
id
),
having_attributes
(
blocking_merge_request_id:
mrs
[
2
].
id
,
blocked_merge_request_id:
mrs
[
3
].
id
)
)
end
end
describe
'.with_blocking_mr_ids'
do
let!
(
:block
)
{
create
(
:merge_request_block
)
}
let!
(
:other_block
)
{
create
(
:merge_request_block
)
}
...
...
ee/spec/services/merge_requests/update_blocks_service_spec.rb
View file @
1e41dc95
...
...
@@ -84,6 +84,16 @@ describe MergeRequests::UpdateBlocksService do
expect
(
merge_request
.
blocking_merge_requests
)
.
to
contain_exactly
(
mr_to_add
,
mr_to_keep
,
hidden_mr
)
end
context
'with a self-referential block'
do
let
(
:mr_to_add
)
{
merge_request
}
it
'ignores the addition'
do
service
.
execute
expect
(
merge_request
.
blocking_merge_requests
).
not_to
include
(
mr_to_add
)
end
end
end
context
'with remove_hidden: true'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment