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
d641d25d
Commit
d641d25d
authored
Jan 14, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add validation to rule models
Ensure MR rule approvals_required > PR rule's
parent
8ea0444f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
1 deletion
+42
-1
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+13
-0
ee/app/models/concerns/approval_rule_like.rb
ee/app/models/concerns/approval_rule_like.rb
+1
-1
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+28
-0
No files found.
ee/app/models/approval_merge_request_rule.rb
View file @
d641d25d
...
...
@@ -15,6 +15,8 @@ class ApprovalMergeRequestRule < ApplicationRecord
has_one
:approval_merge_request_rule_source
has_one
:approval_project_rule
,
through: :approval_merge_request_rule_source
validate
:validate_approvals_required
def
project
merge_request
.
target_project
end
...
...
@@ -44,4 +46,15 @@ class ApprovalMergeRequestRule < ApplicationRecord
!
code_owner?
end
alias_method
:regular?
,
:regular
private
def
validate_approvals_required
return
unless
approval_project_rule
return
unless
approvals_required_changed?
if
approvals_required
<
approval_project_rule
.
approvals_required
errors
.
add
(
:approvals_required
,
:greater_than_or_equal_to
,
count:
approval_project_rule
.
approvals_required
)
end
end
end
ee/app/models/concerns/approval_rule_like.rb
View file @
d641d25d
...
...
@@ -12,7 +12,7 @@ module ApprovalRuleLike
has_many
:group_users
,
->
{
distinct
},
through: :groups
,
source: :users
validates
:name
,
presence:
true
validates
:approvals_required
,
numericality:
{
less_than_or_equal_to:
APPROVALS_REQUIRED_MAX
}
validates
:approvals_required
,
numericality:
{
less_than_or_equal_to:
APPROVALS_REQUIRED_MAX
,
greater_than_or_equal_to:
0
}
end
# Users who are eligible to approve, including specified group members.
...
...
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
d641d25d
...
...
@@ -85,4 +85,32 @@ describe ApprovalMergeRequestRule do
end
end
end
describe
'validations'
do
describe
'approvals_required'
do
subject
{
build
(
:approval_merge_request_rule
,
merge_request:
merge_request
)
}
it
'is a natual number'
do
subject
.
assign_attributes
(
approvals_required:
2
)
expect
(
subject
).
to
be_valid
subject
.
assign_attributes
(
approvals_required:
0
)
expect
(
subject
).
to
be_valid
subject
.
assign_attributes
(
approvals_required:
-
1
)
expect
(
subject
).
to
be_invalid
end
context
'when project rule is present'
do
let
(
:project_rule
)
{
create
(
:approval_project_rule
,
project:
merge_request
.
project
,
approvals_required:
3
)
}
it
'has to be greater than or equal to project rule approvals_required'
do
subject
.
assign_attributes
(
approval_project_rule:
project_rule
,
approvals_required:
2
)
subject
.
valid?
expect
(
subject
.
errors
[
:approvals_required
]).
to
include
(
"must be greater than or equal to 3"
)
end
end
end
end
end
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