Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
d1e08bd3
Commit
d1e08bd3
authored
7 years ago
by
Matt Jankowski
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle nil and blank cases in Account finders (#3500)
parent
dbccdcc1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/concerns/account_finder_concern.rb
+7
-3
7 additions, 3 deletions
app/models/concerns/account_finder_concern.rb
spec/models/concerns/account_finder_concern_spec.rb
+16
-0
16 additions, 0 deletions
spec/models/concerns/account_finder_concern_spec.rb
with
23 additions
and
3 deletions
app/models/concerns/account_finder_concern.rb
+
7
−
3
View file @
d1e08bd3
...
...
@@ -37,21 +37,25 @@ module AccountFinderConcern
def
scoped_accounts
Account
.
unscoped
.
tap
do
|
scope
|
scope
.
merge!
with_usernames
scope
.
merge!
matching_username
scope
.
merge!
matching_domain
end
end
def
with_usernames
Account
.
where
.
not
(
username:
[
nil
,
''
])
end
def
matching_username
raise
(
ActiveRecord
::
RecordNotFound
)
if
username
.
blank?
Account
.
where
(
Account
.
arel_table
[
:username
].
lower
.
eq
username
.
downcase
)
Account
.
where
(
Account
.
arel_table
[
:username
].
lower
.
eq
username
.
to_s
.
downcase
)
end
def
matching_domain
if
domain
.
nil?
Account
.
where
(
domain:
nil
)
else
Account
.
where
(
Account
.
arel_table
[
:domain
].
lower
.
eq
domain
.
downcase
)
Account
.
where
(
Account
.
arel_table
[
:domain
].
lower
.
eq
domain
.
to_s
.
downcase
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/models/concerns/account_finder_concern_spec.rb
+
16
−
0
View file @
d1e08bd3
...
...
@@ -24,6 +24,14 @@ describe AccountFinderConcern do
it
'returns nil for regex style username value'
do
expect
(
Account
.
find_local
(
'al%'
)).
to
be_nil
end
it
'returns nil for nil username value'
do
expect
(
Account
.
find_local
(
nil
)).
to
be_nil
end
it
'returns nil for blank username value'
do
expect
(
Account
.
find_local
(
''
)).
to
be_nil
end
end
describe
'.find_local!'
do
...
...
@@ -70,6 +78,14 @@ describe AccountFinderConcern do
it
'returns nil for regex style domain value'
do
expect
(
Account
.
find_remote
(
'alice'
,
'm%'
)).
to
be_nil
end
it
'returns nil for nil username value'
do
expect
(
Account
.
find_remote
(
nil
,
'domain'
)).
to
be_nil
end
it
'returns nil for blank username value'
do
expect
(
Account
.
find_remote
(
''
,
'domain'
)).
to
be_nil
end
end
describe
'.find_remote!'
do
...
...
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