Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
0ddf825d
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,发现更多精彩内容 >>
提交
0ddf825d
编写于
11月 14, 2016
作者:
J
James Lopez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP - adding a generic entity serializer that should accept a Hash coming from Arel
上级
3b179bc3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
0 deletion
+98
-0
app/serializers/analytics_generic_entity.rb
app/serializers/analytics_generic_entity.rb
+32
-0
app/serializers/analytics_generic_serializer.rb
app/serializers/analytics_generic_serializer.rb
+3
-0
spec/serializers/analytics_generic_entity_spec.rb
spec/serializers/analytics_generic_entity_spec.rb
+39
-0
spec/serializers/analytics_generic_serializer_spec.rb
spec/serializers/analytics_generic_serializer_spec.rb
+24
-0
未找到文件。
app/serializers/analytics_generic_entity.rb
0 → 100644
浏览文件 @
0ddf825d
class
AnalyticsGenericEntity
<
Grape
::
Entity
include
RequestAwareEntity
include
ActionView
::
Helpers
::
DateHelper
expose
:title
expose
:iid
expose
:started_at
,
as: :date
expose
:author
,
using:
UserEntity
expose
:total_time
do
|
object
|
distance_of_time_in_words
(
object
[
:total_time
].
to_f
)
end
expose
(
:date
)
do
|
object
|
interval_in_words
(
object
[
:created_at
])
end
expose
:url
do
|
object
|
url_to
(
"namespace_project_
#{
object
[
:entity
]
}
"
.
to_sym
,
id:
object
[
:iid
].
to_s
)
end
private
def
url_to
(
route
,
id
=
nil
)
public_send
(
"
#{
route
}
_url"
,
options
[
:project
].
namespace
,
options
[
:project
],
id
)
end
def
interval_in_words
(
diff
)
"
#{
distance_of_time_in_words
(
diff
.
to_f
)
}
ago"
end
end
app/serializers/analytics_generic_serializer.rb
0 → 100644
浏览文件 @
0ddf825d
class
AnalyticsGenericSerializer
<
BaseSerializer
entity
AnalyticsGenericEntity
end
spec/serializers/analytics_generic_entity_spec.rb
0 → 100644
浏览文件 @
0ddf825d
require
'spec_helper'
describe
AnalyticsGenericEntity
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:entity_hash
)
{
{
total_time:
"172802.724419"
,
title:
"Eos voluptatem inventore in sed."
,
iid:
"1"
,
id:
"1"
,
created_at:
"2016-11-12 15:04:02.948604"
,
author:
user
,
entity: :merge_request
}
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:entity
)
do
described_class
.
new
(
entity_hash
,
request:
double
,
project:
project
)
end
context
'generic entity'
do
subject
{
entity
.
as_json
}
it
'contains the entity URL'
do
expect
(
subject
).
to
include
(
:url
)
end
it
'contains the author'
do
expect
(
subject
).
to
include
(
:author
)
end
it
'does not contain sensitive information'
do
expect
(
subject
).
not_to
include
(
/token/
)
expect
(
subject
).
not_to
include
(
/variables/
)
end
end
end
spec/serializers/analytics_generic_serializer_spec.rb
0 → 100644
浏览文件 @
0ddf825d
require
'spec_helper'
describe
AnalyticsBuildSerializer
do
let
(
:serializer
)
do
described_class
.
new
(
project:
project
)
.
represent
(
resource
)
end
let
(
:json
)
{
serializer
.
as_json
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:resource
)
{
create
(
:ci_build
)
}
context
'when there is a single object provided'
do
it
'it generates payload for single object'
do
expect
(
json
).
to
be_an_instance_of
Hash
end
it
'contains important elements of analyticsBuild'
do
expect
(
json
)
.
to
include
(
:name
,
:branch
,
:short_sha
,
:date
,
:total_time
,
:url
,
:branch_url
,
:commit_url
,
:author
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录