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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a06410d9
Commit
a06410d9
authored
Aug 26, 2019
by
Aishwarya Subramanian
Committed by
Lin Jen-Shin
Aug 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using before_save method instead of setter
Removed unused method for name setter method
parent
e2251a09
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
2 deletions
+53
-2
app/models/user.rb
app/models/user.rb
+11
-1
changelogs/unreleased/user_name_migration.yml
changelogs/unreleased/user_name_migration.yml
+5
-0
db/migrate/20190820163320_add_first_last_name_to_user.rb
db/migrate/20190820163320_add_first_last_name_to_user.rb
+14
-0
db/schema.rb
db/schema.rb
+3
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+20
-0
No files found.
app/models/user.rb
View file @
a06410d9
...
...
@@ -161,6 +161,8 @@ class User < ApplicationRecord
#
# Note: devise :validatable above adds validations for :email and :password
validates
:name
,
presence:
true
,
length:
{
maximum:
128
}
validates
:first_name
,
length:
{
maximum:
255
}
validates
:last_name
,
length:
{
maximum:
255
}
validates
:email
,
confirmation:
true
validates
:notification_email
,
presence:
true
validates
:notification_email
,
devise_email:
true
,
if:
->
(
user
)
{
user
.
notification_email
!=
user
.
email
}
...
...
@@ -881,7 +883,15 @@ class User < ApplicationRecord
end
def
first_name
name
.
split
.
first
unless
name
.
blank?
read_attribute
(
:first_name
)
||
begin
name
.
split
(
' '
).
first
unless
name
.
blank?
end
end
def
last_name
read_attribute
(
:last_name
)
||
begin
name
.
split
(
' '
).
drop
(
1
).
join
(
' '
)
unless
name
.
blank?
end
end
def
projects_limit_left
...
...
changelogs/unreleased/user_name_migration.yml
0 → 100644
View file @
a06410d9
---
title
:
Add First and Last name columns to User model
merge_request
:
31985
author
:
type
:
added
db/migrate/20190820163320_add_first_last_name_to_user.rb
0 → 100644
View file @
a06410d9
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
AddFirstLastNameToUser
<
ActiveRecord
::
Migration
[
5.2
]
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
def
change
add_column
(
:users
,
:first_name
,
:string
,
null:
true
,
limit:
255
)
add_column
(
:users
,
:last_name
,
:string
,
null:
true
,
limit:
255
)
end
end
db/schema.rb
View file @
a06410d9
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2019_08_
15_093949
)
do
ActiveRecord
::
Schema
.
define
(
version:
2019_08_
20_163320
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"pg_trgm"
...
...
@@ -3511,6 +3511,8 @@ ActiveRecord::Schema.define(version: 2019_08_15_093949) do
t
.
text
"note"
t
.
integer
"roadmap_layout"
,
limit:
2
t
.
integer
"bot_type"
,
limit:
2
t
.
string
"first_name"
,
limit:
255
t
.
string
"last_name"
,
limit:
255
t
.
index
[
"accepted_term_id"
],
name:
"index_users_on_accepted_term_id"
t
.
index
[
"admin"
],
name:
"index_users_on_admin"
t
.
index
[
"bot_type"
],
name:
"index_users_on_bot_type"
...
...
spec/models/user_spec.rb
View file @
a06410d9
...
...
@@ -103,6 +103,14 @@ describe User do
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_at_most
(
128
)
}
end
describe
'first name'
do
it
{
is_expected
.
to
validate_length_of
(
:first_name
).
is_at_most
(
255
)
}
end
describe
'last name'
do
it
{
is_expected
.
to
validate_length_of
(
:last_name
).
is_at_most
(
255
)
}
end
describe
'username'
do
it
'validates presence'
do
expect
(
subject
).
to
validate_presence_of
(
:username
)
...
...
@@ -678,6 +686,18 @@ describe User do
end
end
describe
'name getters'
do
let
(
:user
)
{
create
(
:user
,
name:
'Kane Martin William'
)
}
it
'derives first name from full name, if not present'
do
expect
(
user
.
first_name
).
to
eq
(
'Kane'
)
end
it
'derives last name from full name, if not present'
do
expect
(
user
.
last_name
).
to
eq
(
'Martin William'
)
end
end
describe
'#highest_role'
do
let
(
:user
)
{
create
(
:user
)
}
...
...
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