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
Kazuhiko Shiozaki
gitlab-ce
Commits
5ce6d186
Commit
5ce6d186
authored
Jul 23, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add User.find_by_username!
parent
a364d426
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+1
-1
app/models/user.rb
app/models/user.rb
+4
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+12
-0
No files found.
app/controllers/users_controller.rb
View file @
5ce6d186
...
...
@@ -50,7 +50,7 @@ class UsersController < ApplicationController
private
def
set_user
@user
=
User
.
find_by
!
(
'lower(username) = ?'
,
params
[
:username
].
downcase
)
@user
=
User
.
find_by
_username!
(
params
[
:username
]
)
unless
current_user
||
@user
.
public_profile?
return
authenticate_user!
...
...
app/models/user.rb
View file @
5ce6d186
...
...
@@ -274,6 +274,10 @@ class User < ActiveRecord::Base
value:
login
.
to_s
.
downcase
).
first
end
def
find_by_username!
(
username
)
find_by!
(
'lower(username) = ?'
,
username
.
downcase
)
end
def
by_username_or_id
(
name_or_id
)
where
(
'users.username = ? OR users.id = ?'
,
name_or_id
.
to_s
,
name_or_id
.
to_i
).
first
end
...
...
spec/models/user_spec.rb
View file @
5ce6d186
...
...
@@ -442,6 +442,18 @@ describe User do
end
end
describe
'.find_by_username!'
do
it
'raises RecordNotFound'
do
expect
{
described_class
.
find_by_username!
(
'JohnDoe'
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
it
'is case-insensitive'
do
user
=
create
(
:user
,
username:
'JohnDoe'
)
expect
(
described_class
.
find_by_username!
(
'JOHNDOE'
)).
to
eq
user
end
end
describe
'all_ssh_keys'
do
it
{
is_expected
.
to
have_many
(
:keys
).
dependent
(
:destroy
)
}
...
...
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