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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
e9aefa11
Commit
e9aefa11
authored
Mar 20, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CE] Reduce differences with EE in merge_requests_finder_spec.rb
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
2f381e5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
93 deletions
+109
-93
spec/finders/merge_requests_finder_spec.rb
spec/finders/merge_requests_finder_spec.rb
+44
-93
spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb
...contexts/finders/merge_requests_finder_shared_contexts.rb
+65
-0
No files found.
spec/finders/merge_requests_finder_spec.rb
View file @
e9aefa11
require
'spec_helper'
require
'spec_helper'
describe
MergeRequestsFinder
do
describe
MergeRequestsFinder
do
include
ProjectForksHelper
# We need to explicitly permit Gitaly N+1s because of the specs that use
# :request_store. Gitaly N+1 detection is only enabled when :request_store is,
# but we don't care about potential N+1s when we're just creating several
# projects in the setup phase.
def
create_project_without_n_plus_1
(
*
args
)
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
create
(
:project
,
:public
,
*
args
)
end
end
context
"multiple projects with merge requests"
do
context
"multiple projects with merge requests"
do
let
(
:user
)
{
create
:user
}
include_context
'MergeRequestsFinder multiple projects with merge requests context'
let
(
:user2
)
{
create
:user
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
let
(
:project1
)
{
create_project_without_n_plus_1
(
group:
group
)
}
let
(
:project2
)
do
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
fork_project
(
project1
,
user
)
end
end
let
(
:project3
)
do
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
p
=
fork_project
(
project1
,
user
)
p
.
update!
(
archived:
true
)
p
end
end
let
(
:project4
)
{
create_project_without_n_plus_1
(
:repository
,
group:
subgroup
)
}
let
(
:project5
)
{
create_project_without_n_plus_1
(
group:
subgroup
)
}
let
(
:project6
)
{
create_project_without_n_plus_1
(
group:
subgroup
)
}
let!
(
:merge_request1
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project1
,
target_branch:
'merged-target'
)
}
let!
(
:merge_request2
)
{
create
(
:merge_request
,
:conflict
,
author:
user
,
source_project:
project2
,
target_project:
project1
,
state:
'closed'
)
}
let!
(
:merge_request3
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project2
,
target_project:
project2
,
state:
'locked'
,
title:
'thing WIP thing'
)
}
let!
(
:merge_request4
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project3
,
target_project:
project3
,
title:
'WIP thing'
)
}
let!
(
:merge_request5
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project4
,
target_project:
project4
,
title:
'[WIP]'
)
}
let!
(
:merge_request6
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project5
,
target_project:
project5
,
title:
'WIP: thing'
)
}
let!
(
:merge_request7
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project6
,
target_project:
project6
,
title:
'wip thing'
)
}
let!
(
:merge_request8
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project1
,
target_project:
project1
,
title:
'[wip] thing'
)
}
let!
(
:merge_request9
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project1
,
target_project:
project2
,
title:
'wip: thing'
)
}
before
do
project1
.
add_maintainer
(
user
)
project2
.
add_developer
(
user
)
project3
.
add_developer
(
user
)
project2
.
add_developer
(
user2
)
project4
.
add_developer
(
user
)
project5
.
add_developer
(
user
)
project6
.
add_developer
(
user
)
end
describe
'#execute'
do
describe
'#execute'
do
it
'filters by scope'
do
it
'filters by scope'
do
params
=
{
scope:
'authored'
,
state:
'opened'
}
params
=
{
scope:
'authored'
,
state:
'opened'
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
.
size
).
to
eq
(
7
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request4
,
merge_request5
)
end
end
it
'filters by project'
do
it
'filters by project'
do
params
=
{
project_id:
project1
.
id
,
scope:
'authored'
,
state:
'opened'
}
params
=
{
project_id:
project1
.
id
,
scope:
'authored'
,
state:
'opened'
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
.
size
).
to
eq
(
2
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
)
end
end
it
'filters by commit sha'
do
it
'filters by commit sha'
do
...
@@ -79,24 +31,15 @@ describe MergeRequestsFinder do
...
@@ -79,24 +31,15 @@ describe MergeRequestsFinder do
end
end
context
'filtering by group'
do
context
'filtering by group'
do
it
'includes all merge requests when user has access'
do
it
'includes all merge requests when user has access exceluding merge requests from projects the user does not have access to'
do
params
=
{
group_id:
group
.
id
}
private_project
=
allow_gitaly_n_plus_1
{
create
(
:project
,
:private
,
group:
group
)
}
private_project
.
add_guest
(
user
)
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
.
size
).
to
eq
(
3
)
end
it
'excludes merge requests from projects the user does not have access to'
do
private_project
=
create_project_without_n_plus_1
(
:private
,
group:
group
)
private_mr
=
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
private_project
,
target_project:
private_project
)
private_mr
=
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
private_project
,
target_project:
private_project
)
params
=
{
group_id:
group
.
id
}
params
=
{
group_id:
group
.
id
}
private_project
.
add_guest
(
user
)
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
.
size
).
to
eq
(
3
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
)
expect
(
merge_requests
).
not_to
include
(
private_mr
)
end
end
it
'filters by group including subgroups'
,
:nested_groups
do
it
'filters by group including subgroups'
,
:nested_groups
do
...
@@ -104,14 +47,16 @@ describe MergeRequestsFinder do
...
@@ -104,14 +47,16 @@ describe MergeRequestsFinder do
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
.
size
).
to
eq
(
6
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request5
)
end
end
end
end
it
'filters by non_archived'
do
it
'filters by non_archived'
do
params
=
{
non_archived:
true
}
params
=
{
non_archived:
true
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
.
size
).
to
eq
(
8
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
,
merge_request5
)
end
end
it
'filters by iid'
do
it
'filters by iid'
do
...
@@ -146,41 +91,45 @@ describe MergeRequestsFinder do
...
@@ -146,41 +91,45 @@ describe MergeRequestsFinder do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request3
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request3
)
end
end
it
'filters by wip'
do
describe
'WIP state'
do
params
=
{
wip:
'yes'
}
let!
(
:wip_merge_request1
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project5
,
target_project:
project5
,
title:
'WIP: thing'
)
}
let!
(
:wip_merge_request2
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project6
,
target_project:
project6
,
title:
'wip thing'
)
}
let!
(
:wip_merge_request3
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project1
,
target_project:
project1
,
title:
'[wip] thing'
)
}
let!
(
:wip_merge_request4
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project1
,
target_project:
project2
,
title:
'wip: thing'
)
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
it
'filters by wip'
do
params
=
{
wip:
'yes'
}
expect
(
merge_requests
).
to
contain_exactly
(
merge_request4
,
merge_request5
,
merge_request6
,
merge_request7
,
merge_request8
,
merge_request9
)
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
end
it
'filters by not wip'
do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request4
,
merge_request5
,
wip_merge_request1
,
wip_merge_request2
,
wip_merge_request3
,
wip_merge_request4
)
params
=
{
wip:
'no'
}
end
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
it
'filters by not wip'
do
params
=
{
wip:
'no'
}
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
)
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
end
it
'returns all items if no valid wip param exists'
do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
)
params
=
{
wip:
''
}
end
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
it
'returns all items if no valid wip param exists'
do
params
=
{
wip:
''
}
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
,
merge_request4
,
merge_request5
,
merge_request6
,
merge_request7
,
merge_request8
,
merge_request9
)
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
end
it
'adds wip to scalar params'
do
expect
(
merge_requests
).
to
contain_exactly
(
merge_request1
,
merge_request2
,
merge_request3
,
merge_request4
,
merge_request5
,
wip_merge_request1
,
wip_merge_request2
,
wip_merge_request3
,
wip_merge_request4
)
scalar_params
=
described_class
.
scalar_params
end
it
'adds wip to scalar params'
do
scalar_params
=
described_class
.
scalar_params
expect
(
scalar_params
).
to
include
(
:wip
,
:assignee_id
)
expect
(
scalar_params
).
to
include
(
:wip
,
:assignee_id
)
end
end
end
context
'filtering by group milestone'
do
context
'filtering by group milestone'
do
let!
(
:group
)
{
create
(
:group
,
:public
)
}
let
(
:group_milestone
)
{
create
(
:milestone
,
group:
group
)
}
let
(
:group_milestone
)
{
create
(
:milestone
,
group:
group
)
}
let!
(
:group_member
)
{
create
(
:group_member
,
group:
group
,
user:
user
)
}
let
(
:params
)
{
{
milestone_title:
group_milestone
.
title
}
}
before
do
before
do
project2
.
update
(
namespace:
group
)
project2
.
update
(
namespace:
group
)
...
@@ -188,7 +137,9 @@ describe MergeRequestsFinder do
...
@@ -188,7 +137,9 @@ describe MergeRequestsFinder do
merge_request3
.
update
(
milestone:
group_milestone
)
merge_request3
.
update
(
milestone:
group_milestone
)
end
end
it
'returns issues assigned to that group milestone'
do
it
'returns merge requests assigned to that group milestone'
do
params
=
{
milestone_title:
group_milestone
.
title
}
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
merge_requests
=
described_class
.
new
(
user
,
params
).
execute
expect
(
merge_requests
).
to
contain_exactly
(
merge_request2
,
merge_request3
)
expect
(
merge_requests
).
to
contain_exactly
(
merge_request2
,
merge_request3
)
...
@@ -285,7 +236,7 @@ describe MergeRequestsFinder do
...
@@ -285,7 +236,7 @@ describe MergeRequestsFinder do
it
'returns the number of rows for the default state'
do
it
'returns the number of rows for the default state'
do
finder
=
described_class
.
new
(
user
)
finder
=
described_class
.
new
(
user
)
expect
(
finder
.
row_count
).
to
eq
(
7
)
expect
(
finder
.
row_count
).
to
eq
(
3
)
end
end
it
'returns the number of rows for a given state'
do
it
'returns the number of rows for a given state'
do
...
...
spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb
0 → 100644
View file @
e9aefa11
require
'spec_helper'
RSpec
.
shared_context
'MergeRequestsFinder multiple projects with merge requests context'
do
include
ProjectForksHelper
# We need to explicitly permit Gitaly N+1s because of the specs that use
# :request_store. Gitaly N+1 detection is only enabled when :request_store is,
# but we don't care about potential N+1s when we're just creating several
# projects in the setup phase.
def
allow_gitaly_n_plus_1
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
yield
end
end
set
(
:user
)
{
create
(
:user
)
}
set
(
:user2
)
{
create
(
:user
)
}
set
(
:group
)
{
create
(
:group
)
}
set
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
set
(
:project1
)
do
allow_gitaly_n_plus_1
{
create
(
:project
,
:public
,
group:
group
)
}
end
# We cannot use `set` here otherwise we get:
# Failure/Error: allow(RepositoryForkWorker).to receive(:perform_async).and_return(true)
# The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported.
let
(
:project2
)
do
allow_gitaly_n_plus_1
do
fork_project
(
project1
,
user
)
end
end
let
(
:project3
)
do
allow_gitaly_n_plus_1
do
fork_project
(
project1
,
user
).
tap
do
|
project
|
project
.
update!
(
archived:
true
)
end
end
end
set
(
:project4
)
do
allow_gitaly_n_plus_1
{
create
(
:project
,
:repository
,
group:
subgroup
)
}
end
set
(
:project5
)
do
allow_gitaly_n_plus_1
{
create
(
:project
,
group:
subgroup
)
}
end
set
(
:project6
)
do
allow_gitaly_n_plus_1
{
create
(
:project
,
group:
subgroup
)
}
end
let!
(
:merge_request1
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project1
,
target_branch:
'merged-target'
)
}
let!
(
:merge_request2
)
{
create
(
:merge_request
,
:conflict
,
author:
user
,
source_project:
project2
,
target_project:
project1
,
state:
'closed'
)
}
let!
(
:merge_request3
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project2
,
target_project:
project2
,
state:
'locked'
,
title:
'thing WIP thing'
)
}
let!
(
:merge_request4
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project3
,
target_project:
project3
,
title:
'WIP thing'
)
}
let!
(
:merge_request5
)
{
create
(
:merge_request
,
:simple
,
author:
user
,
source_project:
project4
,
target_project:
project4
,
title:
'[WIP]'
)
}
before
do
project1
.
add_maintainer
(
user
)
project2
.
add_developer
(
user
)
project3
.
add_developer
(
user
)
project4
.
add_developer
(
user
)
project5
.
add_developer
(
user
)
project6
.
add_developer
(
user
)
project2
.
add_developer
(
user2
)
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