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
Tatuya Kamada
gitlab-ce
Commits
0ddf825d
Commit
0ddf825d
authored
Nov 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - adding a generic entity serializer that should accept a Hash coming from Arel
parent
3b179bc3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
0 deletions
+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
No files found.
app/serializers/analytics_generic_entity.rb
0 → 100644
View file @
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
View file @
0ddf825d
class
AnalyticsGenericSerializer
<
BaseSerializer
entity
AnalyticsGenericEntity
end
spec/serializers/analytics_generic_entity_spec.rb
0 → 100644
View file @
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
View file @
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
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