Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a06410d9
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a06410d9
编写于
8月 26, 2019
作者:
A
Aishwarya Subramanian
提交者:
Lin Jen-Shin
8月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Using before_save method instead of setter
Removed unused method for name setter method
上级
e2251a09
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
53 addition
and
2 deletion
+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
未找到文件。
app/models/user.rb
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录