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
65a113a7
Commit
65a113a7
authored
Nov 02, 2020
by
Gary Holtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Removes code that hides a source rule"
This reverts commit
fcc6f275
parent
1ed7e29d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
6 deletions
+73
-6
ee/app/models/approval_state.rb
ee/app/models/approval_state.rb
+1
-1
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+3
-2
ee/spec/models/approval_state_spec.rb
ee/spec/models/approval_state_spec.rb
+3
-3
ee/spec/models/merge_request_spec.rb
ee/spec/models/merge_request_spec.rb
+66
-0
No files found.
ee/app/models/approval_state.rb
View file @
65a113a7
...
...
@@ -205,7 +205,7 @@ class ApprovalState
def
wrapped_rules
strong_memoize
(
:wrapped_rules
)
do
merge_request_rules
=
merge_request
.
approval_rules
.
preload_users
merge_request_rules
=
merge_request
.
approval_rules
.
applicable_to_branch
(
target_branch
)
merge_request_rules
.
map!
do
|
rule
|
ApprovalWrappedRule
.
wrap
(
merge_request
,
rule
)
...
...
ee/app/models/ee/merge_request.rb
View file @
65a113a7
...
...
@@ -20,16 +20,17 @@ module EE
has_many
:approver_users
,
through: :approvers
,
source: :user
has_many
:approver_groups
,
as: :target
,
dependent: :delete_all
# rubocop:disable Cop/ActiveRecordDependent
has_many
:approval_rules
,
class_name:
'ApprovalMergeRequestRule'
,
inverse_of: :merge_request
do
def
preload_users
def
applicable_to_branch
(
branch
)
ActiveRecord
::
Associations
::
Preloader
.
new
.
preload
(
self
,
[
:users
,
:groups
,
approval_project_rule:
[
:users
,
:groups
,
:protected_branches
]]
)
self
.
select
do
|
rule
|
next
true
unless
rule
.
approval_project_rule
.
present?
next
true
if
rule
.
overridden?
rule
rule
.
approval_project_rule
.
applies_to_branch?
(
branch
)
end
end
end
...
...
ee/spec/models/approval_state_spec.rb
View file @
65a113a7
...
...
@@ -1482,9 +1482,9 @@ RSpec.describe ApprovalState do
)
end
it
'returns the rules that are applicable to the merge request'
do
it
'returns the rules that are applicable to the merge request
target branch
'
do
expect
(
subject
.
user_defined_rules
.
map
(
&
:approval_rule
)).
to
eq
([
mr_rule
,
another_mr_rule
another_mr_rule
])
end
...
...
@@ -1493,7 +1493,7 @@ RSpec.describe ApprovalState do
it
'returns the rules that are applicable to the specified target_branch'
do
expect
(
subject
.
user_defined_rules
.
map
(
&
:approval_rule
)).
to
eq
([
mr_rule
,
another_mr_rule
mr_rule
])
end
end
...
...
ee/spec/models/merge_request_spec.rb
View file @
65a113a7
...
...
@@ -27,6 +27,72 @@ RSpec.describe MergeRequest do
it
{
is_expected
.
to
have_many
(
:approval_rules
)
}
it
{
is_expected
.
to
have_many
(
:approval_merge_request_rule_sources
).
through
(
:approval_rules
)
}
it
{
is_expected
.
to
have_many
(
:approval_project_rules
).
through
(
:approval_merge_request_rule_sources
)
}
describe
'approval_rules association'
do
describe
'#applicable_to_branch'
do
let!
(
:rule
)
{
create
(
:approval_merge_request_rule
,
merge_request:
merge_request
)
}
let
(
:branch
)
{
'stable'
}
subject
{
merge_request
.
approval_rules
.
applicable_to_branch
(
branch
)
}
shared_examples_for
'with applicable rules to specified branch'
do
it
{
is_expected
.
to
eq
([
rule
])
}
end
context
'when there are no associated source rules'
do
it_behaves_like
'with applicable rules to specified branch'
end
context
'when there are associated source rules'
do
let
(
:source_rule
)
{
create
(
:approval_project_rule
,
project:
merge_request
.
target_project
)
}
before
do
rule
.
update!
(
approval_project_rule:
source_rule
)
end
context
'and rule is not overridden'
do
before
do
rule
.
update!
(
name:
source_rule
.
name
,
approvals_required:
source_rule
.
approvals_required
,
users:
source_rule
.
users
,
groups:
source_rule
.
groups
)
end
context
'and there are no associated protected branches to source rule'
do
it_behaves_like
'with applicable rules to specified branch'
end
context
'and there are associated protected branches to source rule'
do
before
do
source_rule
.
update!
(
protected_branches:
protected_branches
)
end
context
'and branch matches'
do
let
(
:protected_branches
)
{
[
create
(
:protected_branch
,
name:
branch
)]
}
it_behaves_like
'with applicable rules to specified branch'
end
context
'and branch does not match anything'
do
let
(
:protected_branches
)
{
[
create
(
:protected_branch
,
name:
branch
.
reverse
)]
}
it
{
is_expected
.
to
be_empty
}
end
end
end
context
'and rule is overridden'
do
before
do
rule
.
update!
(
name:
'Overridden Rule'
)
end
it_behaves_like
'with applicable rules to specified branch'
end
end
end
end
end
it_behaves_like
'an editable mentionable with EE-specific mentions'
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