Skip to content
GitLab
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 Community Edition
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
William George
GitLab Community Edition
Commits
9167077c
There was an error fetching the commit references. Please try again later.
Commit
9167077c
authored
6 years ago
by
William George
Browse files
Options
Downloads
Patches
Plain Diff
Refactor `UserFinder.execute` to `UserFinder.find_by_id_or_username`
parent
cb5a2f6e
No related branches found
No related tags found
No related merge requests found
Pipeline
#32554109
passed
6 years ago
Stage: prepare
Stage: test
Stage: post-test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/finders/user_finder.rb
+2
-2
2 additions, 2 deletions
app/finders/user_finder.rb
lib/api/helpers.rb
+1
-1
1 addition, 1 deletion
lib/api/helpers.rb
spec/finders/user_finder_spec.rb
+12
-12
12 additions, 12 deletions
spec/finders/user_finder_spec.rb
with
15 additions
and
15 deletions
app/finders/user_finder.rb
+
2
−
2
View file @
9167077c
...
...
@@ -34,7 +34,7 @@ class UserFinder
end
# Tries to find a User by username or id, returning nil if none could be found.
def
execut
e
def
find_by_id_or_usernam
e
if
input_is_id?
find_by_id
else
...
...
@@ -44,7 +44,7 @@ class UserFinder
# Tries to find a User by username or id, raising a `ActiveRecord::RecordNotFound` if it could
# not be found.
def
execut
e!
def
find_by_id_or_usernam
e!
if
input_is_id?
find_by_id!
else
...
...
This diff is collapsed.
Click to expand it.
lib/api/helpers.rb
+
1
−
1
View file @
9167077c
...
...
@@ -95,7 +95,7 @@ module API
end
def
find_user
(
id
)
UserFinder
.
new
(
id
).
execut
e
UserFinder
.
new
(
id
).
find_by_id_or_usernam
e
end
# rubocop: disable CodeReuse/ActiveRecord
...
...
This diff is collapsed.
Click to expand it.
spec/finders/user_finder_spec.rb
+
12
−
12
View file @
9167077c
...
...
@@ -49,10 +49,10 @@ describe UserFinder do
end
end
describe
'#
execut
e'
do
describe
'#
find_by_id_or_usernam
e'
do
context
'when the user exists (id)'
do
it
'returns the user'
do
found
=
described_class
.
new
(
user
.
id
).
execut
e
found
=
described_class
.
new
(
user
.
id
).
find_by_id_or_usernam
e
expect
(
found
).
to
eq
(
user
)
end
...
...
@@ -60,7 +60,7 @@ describe UserFinder do
context
'when the user exists (id as string)'
do
it
'returns the user'
do
found
=
described_class
.
new
(
user
.
id
.
to_s
).
execut
e
found
=
described_class
.
new
(
user
.
id
.
to_s
).
find_by_id_or_usernam
e
expect
(
found
).
to
eq
(
user
)
end
...
...
@@ -68,7 +68,7 @@ describe UserFinder do
context
'when the user exists (username)'
do
it
'returns the user'
do
found
=
described_class
.
new
(
user
.
username
).
execut
e
found
=
described_class
.
new
(
user
.
username
).
find_by_id_or_usernam
e
expect
(
found
).
to
eq
(
user
)
end
...
...
@@ -76,7 +76,7 @@ describe UserFinder do
context
'when the user does not exist (username)'
do
it
'returns nil'
do
found
=
described_class
.
new
(
"non_existent_username"
).
execut
e
found
=
described_class
.
new
(
"non_existent_username"
).
find_by_id_or_usernam
e
expect
(
found
).
to
be_nil
end
...
...
@@ -84,7 +84,7 @@ describe UserFinder do
context
'when the user does not exist'
do
it
'returns nil'
do
found
=
described_class
.
new
(
1
).
execut
e
found
=
described_class
.
new
(
1
).
find_by_id_or_usernam
e
expect
(
found
).
to
be_nil
end
...
...
@@ -135,10 +135,10 @@ describe UserFinder do
end
end
describe
'#
execut
e!'
do
describe
'#
find_by_id_or_usernam
e!'
do
context
'when the user exists (id)'
do
it
'returns the user'
do
found
=
described_class
.
new
(
user
.
id
).
execut
e!
found
=
described_class
.
new
(
user
.
id
).
find_by_id_or_usernam
e!
expect
(
found
).
to
eq
(
user
)
end
...
...
@@ -146,7 +146,7 @@ describe UserFinder do
context
'when the user exists (id as string)'
do
it
'returns the user'
do
found
=
described_class
.
new
(
user
.
id
.
to_s
).
execut
e!
found
=
described_class
.
new
(
user
.
id
.
to_s
).
find_by_id_or_usernam
e!
expect
(
found
).
to
eq
(
user
)
end
...
...
@@ -154,7 +154,7 @@ describe UserFinder do
context
'when the user exists (username)'
do
it
'returns the user'
do
found
=
described_class
.
new
(
user
.
username
).
execut
e!
found
=
described_class
.
new
(
user
.
username
).
find_by_id_or_usernam
e!
expect
(
found
).
to
eq
(
user
)
end
...
...
@@ -164,7 +164,7 @@ describe UserFinder do
it
'raises ActiveRecord::RecordNotFound'
do
finder
=
described_class
.
new
(
"non_existent_username"
)
expect
{
finder
.
execut
e!
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
finder
.
find_by_id_or_usernam
e!
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
...
...
@@ -172,7 +172,7 @@ describe UserFinder do
it
'raises ActiveRecord::RecordNotFound'
do
finder
=
described_class
.
new
(
1
)
expect
{
finder
.
execut
e!
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
finder
.
find_by_id_or_usernam
e!
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
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