Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
4ab3f265
Commit
4ab3f265
authored
4 years ago
by
Sean Arnold
Browse files
Options
Downloads
Patches
Plain Diff
Update specs to match finder changes
Use attr_writer
parent
14d1bf41
No related branches found
No related tags found
1 merge request
!40220
Issuable parent param refactor
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/finders/issuable_finder.rb
+1
-4
1 addition, 4 deletions
app/finders/issuable_finder.rb
spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb
+48
-21
48 additions, 21 deletions
spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb
with
49 additions
and
25 deletions
app/finders/issuable_finder.rb
+
1
−
4
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 @@ def use_cte_for_search?
end
end
def
parent
=
(
obj
)
@parent
=
obj
end
def
parent_param
=
(
obj
)
@parent
=
obj
params
[
parent_param
]
=
parent
if
parent
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/graphql/loaders/issuable_loader_spec.rb
+
48
−
21
View file @
4ab3f265
...
...
@@ -6,9 +6,44 @@
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
)
{
dou
ble
(
:
finder
,
params:
params
,
execute:
%i[x y
z]
)
}
let
(
:finder
)
{
issua
ble
_
finder
(
params:
params
,
result:
[
:x
,
:y
,
:
z
])
}
where
(
:factory
,
:param_name
)
do
%i[project group]
.
map
{
|
thing
|
[
thing
,
:"
#{
thing
}
_id"
]
}
...
...
@@ -19,7 +54,7 @@
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 @@
describe
'#batching_find_all'
do
context
'the finder params are anything other than [iids]'
do
let
(
:finder
)
{
dou
ble
(
:
finder
,
params:
params
,
execute
:
[
:foo
])
}
let
(
:finder
)
{
issua
ble
_
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 @@
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 @@ def execute
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment