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
d6969410
Commit
d6969410
authored
Jun 03, 2020
by
Nicolas Dular
Committed by
Igor Drozdov
Jun 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
De-dupe refresh service EE spec
parent
5a94623a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
226 additions
and
242 deletions
+226
-242
.rubocop.yml
.rubocop.yml
+0
-2
ee/spec/services/ee/merge_requests/refresh_service_spec.rb
ee/spec/services/ee/merge_requests/refresh_service_spec.rb
+226
-0
ee/spec/services/merge_requests/refresh_service_spec.rb
ee/spec/services/merge_requests/refresh_service_spec.rb
+0
-240
No files found.
.rubocop.yml
View file @
d6969410
...
@@ -251,8 +251,6 @@ GitlabSecurity/PublicSend:
...
@@ -251,8 +251,6 @@ GitlabSecurity/PublicSend:
Gitlab/DuplicateSpecLocation
:
Gitlab/DuplicateSpecLocation
:
Exclude
:
Exclude
:
-
ee/spec/lib/gitlab/gl_repository_spec.rb
-
ee/spec/lib/gitlab/gl_repository_spec.rb
-
ee/spec/services/merge_requests/refresh_service_spec.rb
-
ee/spec/services/ee/merge_requests/refresh_service_spec.rb
Cop/InjectEnterpriseEditionModule
:
Cop/InjectEnterpriseEditionModule
:
Enabled
:
true
Enabled
:
true
...
...
ee/spec/services/ee/merge_requests/refresh_service_spec.rb
View file @
d6969410
...
@@ -211,6 +211,232 @@ describe MergeRequests::RefreshService do
...
@@ -211,6 +211,232 @@ describe MergeRequests::RefreshService do
end
end
end
end
end
end
context
'when user is approver'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project
,
source_branch:
'master'
,
target_branch:
'feature'
,
target_project:
project
,
merge_when_pipeline_succeeds:
true
,
merge_user:
user
)
end
let
(
:forked_project
)
{
fork_project
(
project
,
user
,
repository:
true
)
}
let
(
:forked_merge_request
)
do
create
(
:merge_request
,
source_project:
forked_project
,
source_branch:
'master'
,
target_branch:
'feature'
,
target_project:
project
)
end
let
(
:commits
)
{
merge_request
.
commits
}
let
(
:oldrev
)
{
commits
.
last
.
id
}
let
(
:newrev
)
{
commits
.
first
.
id
}
let
(
:approver
)
{
create
(
:user
)
}
before
do
group
.
add_owner
(
user
)
merge_request
.
approvals
.
create
(
user_id:
user
.
id
)
forked_merge_request
.
approvals
.
create
(
user_id:
user
.
id
)
project
.
add_developer
(
approver
)
perform_enqueued_jobs
do
merge_request
.
update
(
approver_ids:
[
approver
].
map
(
&
:id
).
join
(
','
))
forked_merge_request
.
update
(
approver_ids:
[
approver
].
map
(
&
:id
).
join
(
','
))
end
end
def
approval_todos
(
merge_request
)
Todo
.
where
(
action:
Todo
::
APPROVAL_REQUIRED
,
target:
merge_request
)
end
context
'push to origin repo source branch'
do
let
(
:notification_service
)
{
spy
(
'notification_service'
)
}
before
do
allow
(
service
).
to
receive
(
:execute_hooks
)
allow
(
NotificationService
).
to
receive
(
:new
)
{
notification_service
}
end
it
'resets approvals'
do
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/master'
)
reload_mrs
expect
(
merge_request
.
approvals
).
to
be_empty
expect
(
forked_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
approver
)
expect
(
approval_todos
(
forked_merge_request
)).
to
be_empty
end
end
context
'push to origin repo target branch'
do
context
'when all MRs to the target branch had diffs'
do
before
do
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/feature'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
merge_request
.
approvals
).
not_to
be_empty
expect
(
forked_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
expect
(
approval_todos
(
forked_merge_request
)).
to
be_empty
end
end
end
context
'push to fork repo source branch'
do
let
(
:service
)
{
described_class
.
new
(
forked_project
,
user
)
}
def
refresh
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/master'
)
reload_mrs
end
context
'open fork merge request'
do
it
'resets approvals'
,
:sidekiq_might_not_need_inline
do
refresh
expect
(
merge_request
.
approvals
).
not_to
be_empty
expect
(
forked_merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
expect
(
approval_todos
(
forked_merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
approver
)
end
end
context
'closed fork merge request'
do
before
do
forked_merge_request
.
close!
end
it
'resets approvals'
,
:sidekiq_might_not_need_inline
do
refresh
expect
(
merge_request
.
approvals
).
not_to
be_empty
expect
(
forked_merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
expect
(
approval_todos
(
forked_merge_request
)).
to
be_empty
end
end
end
context
'push to fork repo target branch'
do
describe
'changes to merge requests'
do
before
do
described_class
.
new
(
forked_project
,
user
).
execute
(
oldrev
,
newrev
,
'refs/heads/feature'
)
reload_mrs
end
it
'does not reset approvals'
,
:sidekiq_might_not_need_inline
do
expect
(
merge_request
.
approvals
).
not_to
be_empty
expect
(
forked_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
expect
(
approval_todos
(
forked_merge_request
)).
to
be_empty
end
end
end
context
'push to origin repo target branch after fork project was removed'
do
before
do
forked_project
.
destroy
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/feature'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
merge_request
.
approvals
).
not_to
be_empty
expect
(
forked_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
expect
(
approval_todos
(
forked_merge_request
)).
to
be_empty
end
end
context
'resetting approvals if they are enabled'
do
context
'when approvals_before_merge is disabled'
do
before
do
project
.
update
(
approvals_before_merge:
0
)
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'resets approvals'
do
expect
(
merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
approver
)
end
end
context
'when reset_approvals_on_push is disabled'
do
before
do
project
.
update
(
reset_approvals_on_push:
false
)
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
end
end
context
'when the rebase_commit_sha on the MR matches the pushed SHA'
do
before
do
merge_request
.
update
(
rebase_commit_sha:
newrev
)
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
end
end
context
'when there are approvals'
do
context
'closed merge request'
do
before
do
merge_request
.
close!
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'resets the approvals'
do
expect
(
merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
merge_request
)).
to
be_empty
end
end
context
'opened merge request'
do
before
do
allow
(
service
).
to
receive
(
:execute_hooks
)
service
.
execute
(
oldrev
,
newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'resets the approvals'
do
expect
(
merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
approver
)
end
end
end
end
def
reload_mrs
merge_request
.
reload
forked_merge_request
.
reload
end
end
end
end
describe
'#abort_ff_merge_requests_with_when_pipeline_succeeds'
do
describe
'#abort_ff_merge_requests_with_when_pipeline_succeeds'
do
...
...
ee/spec/services/merge_requests/refresh_service_spec.rb
deleted
100644 → 0
View file @
5a94623a
# frozen_string_literal: true
require
'spec_helper'
describe
MergeRequests
::
RefreshService
do
include
ProjectForksHelper
let
(
:service
)
{
described_class
}
describe
'#execute'
do
before
do
@user
=
create
(
:user
)
group
=
create
(
:group
)
group
.
add_owner
(
@user
)
@project
=
create
(
:project
,
:repository
,
namespace:
group
,
approvals_before_merge:
1
,
reset_approvals_on_push:
true
)
@fork_project
=
fork_project
(
@project
,
@user
,
repository:
true
)
@merge_request
=
create
(
:merge_request
,
source_project:
@project
,
source_branch:
'master'
,
target_branch:
'feature'
,
target_project:
@project
,
merge_when_pipeline_succeeds:
true
,
merge_user:
@user
)
@fork_merge_request
=
create
(
:merge_request
,
source_project:
@fork_project
,
source_branch:
'master'
,
target_branch:
'feature'
,
target_project:
@project
)
@merge_request
.
approvals
.
create
(
user_id:
@user
.
id
)
@fork_merge_request
.
approvals
.
create
(
user_id:
@user
.
id
)
@commits
=
@merge_request
.
commits
@oldrev
=
@commits
.
last
.
id
@newrev
=
@commits
.
first
.
id
@approver
=
create
(
:user
)
@project
.
add_developer
(
@approver
)
perform_enqueued_jobs
do
@merge_request
.
update
(
approver_ids:
[
@approver
].
map
(
&
:id
).
join
(
','
))
@fork_merge_request
.
update
(
approver_ids:
[
@approver
].
map
(
&
:id
).
join
(
','
))
end
end
def
approval_todos
(
merge_request
)
Todo
.
where
(
action:
Todo
::
APPROVAL_REQUIRED
,
target:
merge_request
)
end
context
'push to origin repo source branch'
do
let
(
:refresh_service
)
{
service
.
new
(
@project
,
@user
)
}
let
(
:notification_service
)
{
spy
(
'notification_service'
)
}
before
do
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
allow
(
NotificationService
).
to
receive
(
:new
)
{
notification_service
}
end
it
'resets approvals'
do
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
expect
(
@merge_request
.
approvals
).
to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
@merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
@approver
)
expect
(
approval_todos
(
@fork_merge_request
)).
to
be_empty
end
end
context
'push to origin repo target branch'
do
context
'when all MRs to the target branch had diffs'
do
before
do
service
.
new
(
@project
,
@user
).
execute
(
@oldrev
,
@newrev
,
'refs/heads/feature'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
expect
(
approval_todos
(
@fork_merge_request
)).
to
be_empty
end
end
end
context
'push to fork repo source branch'
do
let
(
:refresh_service
)
{
service
.
new
(
@fork_project
,
@user
)
}
def
refresh
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
context
'open fork merge request'
do
it
'resets approvals'
,
:sidekiq_might_not_need_inline
do
refresh
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
expect
(
approval_todos
(
@fork_merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
@approver
)
end
end
context
'closed fork merge request'
do
before
do
@fork_merge_request
.
close!
end
it
'resets approvals'
,
:sidekiq_might_not_need_inline
do
refresh
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
expect
(
approval_todos
(
@fork_merge_request
)).
to
be_empty
end
end
end
context
'push to fork repo target branch'
do
describe
'changes to merge requests'
do
before
do
service
.
new
(
@fork_project
,
@user
).
execute
(
@oldrev
,
@newrev
,
'refs/heads/feature'
)
reload_mrs
end
it
'does not reset approvals'
,
:sidekiq_might_not_need_inline
do
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
expect
(
approval_todos
(
@fork_merge_request
)).
to
be_empty
end
end
end
context
'push to origin repo target branch after fork project was removed'
do
before
do
@fork_project
.
destroy
service
.
new
(
@project
,
@user
).
execute
(
@oldrev
,
@newrev
,
'refs/heads/feature'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
expect
(
approval_todos
(
@fork_merge_request
)).
to
be_empty
end
end
context
'resetting approvals if they are enabled'
do
context
'when approvals_before_merge is disabled'
do
before
do
@project
.
update
(
approvals_before_merge:
0
)
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'resets approvals'
do
expect
(
@merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
@merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
@approver
)
end
end
context
'when reset_approvals_on_push is disabled'
do
before
do
@project
.
update
(
reset_approvals_on_push:
false
)
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
end
end
context
'when the rebase_commit_sha on the MR matches the pushed SHA'
do
before
do
@merge_request
.
update
(
rebase_commit_sha:
@newrev
)
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'does not reset approvals'
do
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
end
end
context
'when there are approvals'
do
context
'closed merge request'
do
before
do
@merge_request
.
close!
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'resets the approvals'
do
expect
(
@merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
@merge_request
)).
to
be_empty
end
end
context
'opened merge request'
do
before
do
refresh_service
=
service
.
new
(
@project
,
@user
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
reload_mrs
end
it
'resets the approvals'
do
expect
(
@merge_request
.
approvals
).
to
be_empty
expect
(
approval_todos
(
@merge_request
).
map
(
&
:user
)).
to
contain_exactly
(
@approver
)
end
end
end
end
def
reload_mrs
@merge_request
.
reload
@fork_merge_request
.
reload
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