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
febef4e8
Commit
febef4e8
authored
Aug 12, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up push_options_handler_service_spec
Use let_it_be to create a project once
parent
2f94aec4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
25 deletions
+8
-25
spec/services/merge_requests/push_options_handler_service_spec.rb
...vices/merge_requests/push_options_handler_service_spec.rb
+8
-25
No files found.
spec/services/merge_requests/push_options_handler_service_spec.rb
View file @
febef4e8
...
@@ -5,9 +5,10 @@ require 'spec_helper'
...
@@ -5,9 +5,10 @@ require 'spec_helper'
RSpec
.
describe
MergeRequests
::
PushOptionsHandlerService
do
RSpec
.
describe
MergeRequests
::
PushOptionsHandlerService
do
include
ProjectForksHelper
include
ProjectForksHelper
let
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
let_it_be
(
:user
)
{
create
(
:user
,
developer_projects:
[
project
])
}
let
(
:forked_project
)
{
fork_project
(
project
,
user
,
repository:
true
)
}
let_it_be
(
:forked_project
)
{
fork_project
(
project
,
user
,
repository:
true
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
changes
,
push_options
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
changes
,
push_options
)
}
let
(
:source_branch
)
{
'fix'
}
let
(
:source_branch
)
{
'fix'
}
let
(
:target_branch
)
{
'feature'
}
let
(
:target_branch
)
{
'feature'
}
...
@@ -21,28 +22,14 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
...
@@ -21,28 +22,14 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
let
(
:deleted_branch_changes
)
{
"d14d6c0abdd253381df51a723d58691b2ee1ab08
#{
Gitlab
::
Git
::
BLANK_SHA
}
refs/heads/
#{
source_branch
}
"
}
let
(
:deleted_branch_changes
)
{
"d14d6c0abdd253381df51a723d58691b2ee1ab08
#{
Gitlab
::
Git
::
BLANK_SHA
}
refs/heads/
#{
source_branch
}
"
}
let
(
:default_branch_changes
)
{
"d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/
#{
project
.
default_branch
}
"
}
let
(
:default_branch_changes
)
{
"d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/
#{
project
.
default_branch
}
"
}
before
do
project
.
add_developer
(
user
)
end
shared_examples_for
'a service that can create a merge request'
do
shared_examples_for
'a service that can create a merge request'
do
subject
(
:last_mr
)
{
MergeRequest
.
last
}
subject
(
:last_mr
)
{
MergeRequest
.
last
}
it
'creates a merge request'
do
it
'creates a merge request with the correct target branch and assigned user'
do
expect
{
service
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
end
it
'sets the correct target branch'
do
branch
=
push_options
[
:target
]
||
project
.
default_branch
branch
=
push_options
[
:target
]
||
project
.
default_branch
service
.
execute
expect
{
service
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
expect
(
last_mr
.
target_branch
).
to
eq
(
branch
)
expect
(
last_mr
.
target_branch
).
to
eq
(
branch
)
end
it
'assigns the MR to the user'
do
service
.
execute
expect
(
last_mr
.
assignees
).
to
contain_exactly
(
user
)
expect
(
last_mr
.
assignees
).
to
contain_exactly
(
user
)
end
end
...
@@ -54,15 +41,10 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
...
@@ -54,15 +41,10 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
allow
(
forked_project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
allow
(
forked_project
).
to
receive
(
:empty_repo?
).
and_return
(
false
)
end
end
it
'sets the correct source project'
do
it
'sets the correct source
and target
project'
do
service
.
execute
service
.
execute
expect
(
last_mr
.
source_project
).
to
eq
(
forked_project
)
expect
(
last_mr
.
source_project
).
to
eq
(
forked_project
)
end
it
'sets the correct target project'
do
service
.
execute
expect
(
last_mr
.
target_project
).
to
eq
(
project
)
expect
(
last_mr
.
target_project
).
to
eq
(
project
)
end
end
end
end
...
@@ -746,6 +728,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
...
@@ -746,6 +728,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
end
end
describe
'when MRs are not enabled'
do
describe
'when MRs are not enabled'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
).
tap
{
|
pr
|
pr
.
add_developer
(
user
)
}
}
let
(
:push_options
)
{
{
create:
true
}
}
let
(
:push_options
)
{
{
create:
true
}
}
let
(
:changes
)
{
new_branch_changes
}
let
(
:changes
)
{
new_branch_changes
}
...
...
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