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
4ab3f265
Commit
4ab3f265
authored
Aug 24, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update specs to match finder changes
Use attr_writer
parent
14d1bf41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
25 deletions
+49
-25
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+1
-4
spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb
spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb
+48
-21
No files found.
app/finders/issuable_finder.rb
View file @
4ab3f265
...
...
@@ -44,6 +44,7 @@ class IssuableFinder
NEGATABLE_PARAMS_HELPER_KEYS
=
%i[project_id scope status include_subgroups]
.
freeze
attr_accessor
:current_user
,
:params
attr_writer
:parent
delegate
(
*
%i[assignee milestones]
,
to: :params
)
...
...
@@ -204,10 +205,6 @@ class IssuableFinder
end
end
def
parent
=
(
obj
)
@parent
=
obj
end
def
parent_param
=
(
obj
)
@parent
=
obj
params
[
parent_param
]
=
parent
if
parent
...
...
spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb
View file @
4ab3f265
...
...
@@ -6,9 +6,44 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
subject
{
described_class
.
new
(
parent
,
finder
)
}
let
(
:params
)
{
HashWithIndifferentAccess
.
new
}
let
(
:finder_params
)
{
finder
.
params
.
to_h
.
with_indifferent_access
}
# Dumb finder class, that only implements what we need, and has
# predictable query counts.
let
(
:finder_class
)
do
Class
.
new
do
attr_reader
:current_user
,
:params
attr_accessor
:parent
def
initialize
(
user
,
args
)
@current_user
=
user
@params
=
HashWithIndifferentAccess
.
new
(
args
.
to_h
)
end
def
execute
params
[
:project_id
].
issues
.
where
(
iid:
params
[
:iids
])
end
def
parent_param
=
(
obj
)
@parent
=
obj
params
[
parent_param
]
=
parent
if
parent
end
def
parent_param
case
parent
when
Project
:project_id
when
Group
:group_id
else
raise
"Unexpected parent:
#{
parent
.
class
}
"
end
end
end
end
describe
'#find_all'
do
let
(
:finder
)
{
double
(
:finder
,
params:
params
,
execute:
%i[x y
z]
)
}
let
(
:finder
)
{
issuable_finder
(
params:
params
,
result:
[
:x
,
:y
,
:
z
])
}
where
(
:factory
,
:param_name
)
do
%i[project group]
.
map
{
|
thing
|
[
thing
,
:"
#{
thing
}
_id"
]
}
...
...
@@ -19,7 +54,7 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
it
'assignes the parent parameter, and batching_find_alls the finder'
do
expect
(
subject
.
find_all
).
to
contain_exactly
(
:x
,
:y
,
:z
)
expect
(
params
).
to
include
(
param_name
=>
parent
)
expect
(
finder_
params
).
to
include
(
param_name
=>
parent
)
end
end
...
...
@@ -34,12 +69,12 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
describe
'#batching_find_all'
do
context
'the finder params are anything other than [iids]'
do
let
(
:finder
)
{
double
(
:finder
,
params:
params
,
execute
:
[
:foo
])
}
let
(
:finder
)
{
issuable_finder
(
params:
params
,
result
:
[
:foo
])
}
let
(
:parent
)
{
build_stubbed
(
:project
)
}
it
'batching_find_alls the finder, setting the correct parent parameter'
do
expect
(
subject
.
batching_find_all
).
to
eq
([
:foo
])
expect
(
params
[
:project_id
]).
to
eq
(
parent
)
expect
(
finder_
params
[
:project_id
]).
to
eq
(
parent
)
end
it
'allows a post-process block'
do
...
...
@@ -48,23 +83,6 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
end
context
'the finder params are exactly [iids]'
do
# Dumb finder class, that only implements what we need, and has
# predictable query counts.
let
(
:finder_class
)
do
Class
.
new
do
attr_reader
:current_user
,
:params
def
initialize
(
user
,
args
)
@current_user
=
user
@params
=
HashWithIndifferentAccess
.
new
(
args
.
to_h
)
end
def
execute
params
[
:project_id
].
issues
.
where
(
iid:
params
[
:iids
])
end
end
end
it
'batches requests'
do
issue_a
=
create
(
:issue
)
issue_b
=
create
(
:issue
)
...
...
@@ -93,4 +111,13 @@ RSpec.describe Gitlab::Graphql::Loaders::IssuableLoader do
end
end
end
private
def
issuable_finder
(
user:
double
(
:user
),
params:
{},
result:
nil
)
new_finder
=
finder_class
.
new
(
user
,
params
)
allow
(
new_finder
).
to
receive
(
:execute
).
and_return
(
result
)
if
result
new_finder
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