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
711c91dc
Commit
711c91dc
authored
Apr 04, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract EE-specific tests for MR refresh service
parent
6092ff56
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
213 additions
and
98 deletions
+213
-98
ee/spec/services/merge_requests/refresh_service_spec.rb
ee/spec/services/merge_requests/refresh_service_spec.rb
+211
-0
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+2
-98
No files found.
ee/spec/services/merge_requests/refresh_service_spec.rb
0 → 100644
View file @
711c91dc
# 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
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
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
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'
do
refresh
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
to
be_empty
end
end
context
'closed fork merge request'
do
before
do
@fork_merge_request
.
close!
end
it
'resets approvals'
do
refresh
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
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'
do
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_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
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
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
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
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
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
end
end
end
end
def
reload_mrs
@merge_request
.
reload
@fork_merge_request
.
reload
end
end
end
spec/services/merge_requests/refresh_service_spec.rb
View file @
711c91dc
...
...
@@ -13,7 +13,7 @@ describe MergeRequests::RefreshService do
group
=
create
(
:group
)
group
.
add_owner
(
@user
)
@project
=
create
(
:project
,
:repository
,
namespace:
group
,
approvals_before_merge:
1
,
reset_approvals_on_push:
true
)
@project
=
create
(
:project
,
:repository
,
namespace:
group
)
@fork_project
=
fork_project
(
@project
,
@user
,
repository:
true
)
@merge_request
=
create
(
:merge_request
,
...
...
@@ -38,9 +38,6 @@ describe MergeRequests::RefreshService do
target_branch:
'feature'
,
target_project:
@project
)
@merge_request
.
approvals
.
create
(
user_id:
user
.
id
)
@fork_merge_request
.
approvals
.
create
(
user_id:
user
.
id
)
@build_failed_todo
=
create
(
:todo
,
:build_failed
,
user:
@user
,
...
...
@@ -90,9 +87,6 @@ describe MergeRequests::RefreshService do
expect
(
@fork_merge_request
.
notes
).
to
be_empty
expect
(
@build_failed_todo
).
to
be_done
expect
(
@fork_build_failed_todo
).
to
be_done
# EE-only
expect
(
@merge_request
.
approvals
).
to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_to
be_empty
end
it
'reloads source branch MRs memoization'
do
...
...
@@ -275,13 +269,11 @@ describe MergeRequests::RefreshService do
end
end
context
'push to origin repo source branch
when an MR was reopened
'
do
context
'push to origin repo source branch'
do
let
(
:refresh_service
)
{
service
.
new
(
@project
,
@user
)
}
let
(
:notification_service
)
{
spy
(
'notification_service'
)
}
before
do
@merge_request
.
update
(
state: :opened
)
allow
(
refresh_service
).
to
receive
(
:execute_hooks
)
allow
(
NotificationService
).
to
receive
(
:new
)
{
notification_service
}
refresh_service
.
execute
(
@oldrev
,
@newrev
,
'refs/heads/master'
)
...
...
@@ -321,9 +313,6 @@ describe MergeRequests::RefreshService do
expect
(
@fork_merge_request
.
notes
.
last
.
note
).
to
include
(
'merged'
)
expect
(
@build_failed_todo
).
to
be_done
expect
(
@fork_build_failed_todo
).
to
be_done
# EE-only
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_to
be_empty
end
end
...
...
@@ -402,9 +391,6 @@ describe MergeRequests::RefreshService do
expect
(
@fork_merge_request
).
to
be_open
expect
(
@build_failed_todo
).
to
be_pending
expect
(
@fork_build_failed_todo
).
to
be_pending
# EE-only
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
to
be_empty
end
it
'outdates opened forked MR suggestions'
do
...
...
@@ -436,9 +422,6 @@ describe MergeRequests::RefreshService do
expect
(
@fork_merge_request
).
to
be_closed
expect
(
@build_failed_todo
).
to
be_pending
expect
(
@fork_build_failed_todo
).
to
be_pending
# EE-only
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
to
be_empty
end
end
end
...
...
@@ -457,9 +440,6 @@ describe MergeRequests::RefreshService do
expect
(
@fork_merge_request
).
to
be_open
expect
(
@build_failed_todo
).
to
be_pending
expect
(
@fork_build_failed_todo
).
to
be_pending
# EE-only
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_to
be_empty
end
end
...
...
@@ -546,82 +526,6 @@ describe MergeRequests::RefreshService do
expect
(
@fork_merge_request
.
notes
).
to
be_empty
expect
(
@build_failed_todo
).
to
be_done
expect
(
@fork_build_failed_todo
).
to
be_done
# EE-only
expect
(
@merge_request
.
approvals
).
not_to
be_empty
expect
(
@fork_merge_request
.
approvals
).
not_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
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
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
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
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
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