BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0c1d9125
Commit
0c1d9125
authored
Jul 24, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'rs-issue-2012' into 'master'
Make username parameter for Users#show case-insensitive Closes #2012 See merge request !996
parents
7e262ebf
5ce6d186
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
10 deletions
+41
-10
user.rb
app/models/user.rb
+4
-0
users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+25
-10
user_spec.rb
spec/models/user_spec.rb
+12
-0
No files found.
app/models/user.rb
View file @
0c1d9125
...
...
@@ -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/controllers/users_controller_spec.rb
View file @
0c1d9125
require
'spec_helper'
describe
UsersController
do
let
(
:user
)
{
create
(
:user
,
username:
'user1'
,
name:
'User 1'
,
email:
'user1@gitlab.com'
)
}
before
do
sign_in
(
user
)
end
let
(
:user
)
{
create
(
:user
)
}
describe
'GET #show'
do
render_views
it
'is case-insensitive'
do
user
=
create
(
:user
,
username:
'CamelCaseUser'
)
sign_in
(
user
)
get
:show
,
username:
user
.
username
.
downcase
it
'renders the show template'
do
get
:show
,
username:
user
.
username
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
render_template
(
'show'
)
expect
(
response
).
to
be_success
end
context
'with rendered views'
do
render_views
it
'renders the show template'
do
sign_in
(
user
)
get
:show
,
username:
user
.
username
expect
(
response
).
to
be_success
expect
(
response
).
to
render_template
(
'show'
)
end
end
end
describe
'GET #calendar'
do
it
'renders calendar'
do
sign_in
(
user
)
get
:calendar
,
username:
user
.
username
expect
(
response
).
to
render_template
(
'calendar'
)
end
end
...
...
@@ -30,6 +43,8 @@ describe UsersController do
before
do
allow_any_instance_of
(
User
).
to
receive
(
:contributed_projects_ids
).
and_return
([
project
.
id
])
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
end
...
...
spec/models/user_spec.rb
View file @
0c1d9125
...
...
@@ -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