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
9d12db03
Commit
9d12db03
authored
Sep 22, 2020
by
Gary Holtz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using a more efficient way to check for group/user equality
parent
cd53569c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
7 deletions
+39
-7
ee/app/models/approval_merge_request_rule.rb
ee/app/models/approval_merge_request_rule.rb
+8
-2
ee/spec/models/approval_merge_request_rule_spec.rb
ee/spec/models/approval_merge_request_rule_spec.rb
+26
-0
spec/lib/gitlab/background_migration/add_modified_to_approval_merge_request_rule_spec.rb
...ation/add_modified_to_approval_merge_request_rule_spec.rb
+5
-5
No files found.
ee/app/models/approval_merge_request_rule.rb
View file @
9d12db03
...
@@ -140,11 +140,17 @@ class ApprovalMergeRequestRule < ApplicationRecord
...
@@ -140,11 +140,17 @@ class ApprovalMergeRequestRule < ApplicationRecord
private
private
def
different_groups?
def
different_groups?
groups
.
sort
!=
approval_project_rule
.
groups
.
sort
group_ids
=
groups
.
collect
(
&
:id
)
apr_group_ids
=
approval_project_rule
.
groups
.
pluck
(
:id
)
group_ids
&
apr_group_ids
==
group_ids
end
end
def
different_users?
def
different_users?
users
.
sort
!=
approval_project_rule
.
users
.
sort
user_ids
=
users
.
collect
(
&
:id
)
apr_user_ids
=
approval_project_rule
.
users
.
pluck
(
:id
)
user_ids
&
apr_user_ids
==
user_ids
end
end
def
different_name_or_approvals_required?
def
different_name_or_approvals_required?
...
...
ee/spec/models/approval_merge_request_rule_spec.rb
View file @
9d12db03
...
@@ -36,6 +36,32 @@ RSpec.describe ApprovalMergeRequestRule do
...
@@ -36,6 +36,32 @@ RSpec.describe ApprovalMergeRequestRule do
it
'is valid'
do
it
'is valid'
do
expect
(
merge_request_rule
).
to
be_valid
expect
(
merge_request_rule
).
to
be_valid
end
end
context
'the MR rule shows that its modified from the original'
do
it
'by having different groups'
do
first_group
=
create
(
:group
)
second_group
=
create
(
:group
)
third_group
=
create
(
:group
)
approval_project_rule
.
groups
=
[
first_group
,
second_group
]
approval_project_rule
.
save!
merge_request_rule
.
groups
=
[
first_group
,
third_group
]
expect
(
merge_request_rule
.
different_from_project_rule?
).
to
be
true
end
it
'by having different users'
do
first_user
=
create
(
:user
)
second_user
=
create
(
:user
)
third_user
=
create
(
:user
)
approval_project_rule
.
users
=
[
first_user
,
second_user
]
approval_project_rule
.
save!
merge_request_rule
.
users
=
[
first_user
,
third_user
]
expect
(
merge_request_rule
.
different_from_project_rule?
).
to
be
true
end
end
end
end
context
'when the project of approval_project_rule and merge request does not match'
do
context
'when the project of approval_project_rule and merge request does not match'
do
...
...
spec/lib/gitlab/background_migration/add_modified_to_approval_merge_request_rule_spec.rb
View file @
9d12db03
...
@@ -33,16 +33,16 @@ RSpec.describe Gitlab::BackgroundMigration::AddModifiedToApprovalMergeRequestRul
...
@@ -33,16 +33,16 @@ RSpec.describe Gitlab::BackgroundMigration::AddModifiedToApprovalMergeRequestRul
sources
.
create!
(
approval_project_rule_id:
overridden_project_rule
.
id
,
approval_merge_request_rule_id:
overridden_merge_rule
.
id
)
sources
.
create!
(
approval_project_rule_id:
overridden_project_rule
.
id
,
approval_merge_request_rule_id:
overridden_merge_rule
.
id
)
sources
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
approval_merge_request_rule_id:
overridden_merge_rule_two
.
id
)
sources
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
approval_merge_request_rule_id:
overridden_merge_rule_two
.
id
)
group1
=
groups
.
create!
(
name:
"1"
,
path:
"test_group1"
,
type:
'Group'
)
group1
=
groups
.
create!
(
name:
"
group
1"
,
path:
"test_group1"
,
type:
'Group'
)
group2
=
groups
.
create!
(
name:
"2"
,
path:
"test_group2"
,
type:
'Group'
)
group2
=
groups
.
create!
(
name:
"
group
2"
,
path:
"test_group2"
,
type:
'Group'
)
group3
=
groups
.
create!
(
name:
"3"
,
path:
"test_group3"
,
type:
'Group'
)
group3
=
groups
.
create!
(
name:
"
group
3"
,
path:
"test_group3"
,
type:
'Group'
)
project_groups
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
group_id:
group1
.
id
)
project_groups
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
group_id:
group1
.
id
)
project_groups
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
group_id:
group2
.
id
)
project_groups
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
group_id:
group2
.
id
)
project_groups
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
group_id:
group3
.
id
)
project_groups
.
create!
(
approval_project_rule_id:
overridden_project_rule_two
.
id
,
group_id:
group3
.
id
)
mr_groups
.
create!
(
approval_merge_request_rule_id:
overridden_
project_rule_two
.
id
,
group_id:
group1
.
id
)
mr_groups
.
create!
(
approval_merge_request_rule_id:
overridden_
merge_rule
.
id
,
group_id:
group1
.
id
)
mr_groups
.
create!
(
approval_merge_request_rule_id:
overridden_
project
_rule_two
.
id
,
group_id:
group2
.
id
)
mr_groups
.
create!
(
approval_merge_request_rule_id:
overridden_
merge
_rule_two
.
id
,
group_id:
group2
.
id
)
end
end
describe
'#perform'
do
describe
'#perform'
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