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
42e3f0fd
Commit
42e3f0fd
authored
Jan 27, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return serializable hash from a represented serializer
parent
256a7735
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
40 deletions
+29
-40
app/serializers/base_serializer.rb
app/serializers/base_serializer.rb
+1
-0
spec/serializers/analytics_build_serializer_spec.rb
spec/serializers/analytics_build_serializer_spec.rb
+3
-7
spec/serializers/analytics_issue_serializer_spec.rb
spec/serializers/analytics_issue_serializer_spec.rb
+2
-3
spec/serializers/analytics_merge_request_serializer_spec.rb
spec/serializers/analytics_merge_request_serializer_spec.rb
+2
-3
spec/serializers/analytics_stage_serializer_spec.rb
spec/serializers/analytics_stage_serializer_spec.rb
+7
-7
spec/serializers/analytics_summary_serializer_spec.rb
spec/serializers/analytics_summary_serializer_spec.rb
+9
-10
spec/serializers/environment_serializer_spec.rb
spec/serializers/environment_serializer_spec.rb
+4
-5
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+1
-5
No files found.
app/serializers/base_serializer.rb
View file @
42e3f0fd
...
@@ -6,6 +6,7 @@ class BaseSerializer
...
@@ -6,6 +6,7 @@ class BaseSerializer
def
represent
(
resource
,
opts
=
{})
def
represent
(
resource
,
opts
=
{})
self
.
class
.
entity_class
self
.
class
.
entity_class
.
represent
(
resource
,
opts
.
merge
(
request:
@request
))
.
represent
(
resource
,
opts
.
merge
(
request:
@request
))
.
as_json
end
end
def
self
.
entity
(
entity_class
)
def
self
.
entity
(
entity_class
)
...
...
spec/serializers/analytics_build_serializer_spec.rb
View file @
42e3f0fd
require
'spec_helper'
require
'spec_helper'
describe
AnalyticsBuildSerializer
do
describe
AnalyticsBuildSerializer
do
let
(
:serializer
)
do
described_class
.
new
.
represent
(
resource
)
end
let
(
:json
)
{
serializer
.
as_json
}
let
(
:resource
)
{
create
(
:ci_build
)
}
let
(
:resource
)
{
create
(
:ci_build
)
}
subject
{
described_class
.
new
.
represent
(
resource
)
}
context
'when there is a single object provided'
do
context
'when there is a single object provided'
do
it
'contains important elements of analyticsBuild'
do
it
'contains important elements of analyticsBuild'
do
expect
(
json
)
expect
(
subject
)
.
to
include
(
:name
,
:branch
,
:short_sha
,
:date
,
:total_time
,
:url
,
:author
)
.
to
include
(
:name
,
:branch
,
:short_sha
,
:date
,
:total_time
,
:url
,
:author
)
end
end
end
end
...
...
spec/serializers/analytics_issue_serializer_spec.rb
View file @
42e3f0fd
require
'spec_helper'
require
'spec_helper'
describe
AnalyticsIssueSerializer
do
describe
AnalyticsIssueSerializer
do
let
(
:serializer
)
do
subject
do
described_class
described_class
.
new
(
project:
project
,
entity: :merge_request
)
.
new
(
project:
project
,
entity: :merge_request
)
.
represent
(
resource
)
.
represent
(
resource
)
end
end
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:json
)
{
serializer
.
as_json
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:resource
)
do
let
(
:resource
)
do
{
{
...
@@ -23,7 +22,7 @@ describe AnalyticsIssueSerializer do
...
@@ -23,7 +22,7 @@ describe AnalyticsIssueSerializer do
context
'when there is a single object provided'
do
context
'when there is a single object provided'
do
it
'contains important elements of the issue'
do
it
'contains important elements of the issue'
do
expect
(
json
).
to
include
(
:title
,
:iid
,
:created_at
,
:total_time
,
:url
,
:author
)
expect
(
subject
).
to
include
(
:title
,
:iid
,
:created_at
,
:total_time
,
:url
,
:author
)
end
end
end
end
end
end
spec/serializers/analytics_merge_request_serializer_spec.rb
View file @
42e3f0fd
require
'spec_helper'
require
'spec_helper'
describe
AnalyticsMergeRequestSerializer
do
describe
AnalyticsMergeRequestSerializer
do
let
(
:serializer
)
do
subject
do
described_class
described_class
.
new
(
project:
project
,
entity: :merge_request
)
.
new
(
project:
project
,
entity: :merge_request
)
.
represent
(
resource
)
.
represent
(
resource
)
end
end
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:json
)
{
serializer
.
as_json
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:resource
)
do
let
(
:resource
)
do
{
{
...
@@ -24,7 +23,7 @@ describe AnalyticsMergeRequestSerializer do
...
@@ -24,7 +23,7 @@ describe AnalyticsMergeRequestSerializer do
context
'when there is a single object provided'
do
context
'when there is a single object provided'
do
it
'contains important elements of the merge request'
do
it
'contains important elements of the merge request'
do
expect
(
json
).
to
include
(
:title
,
:iid
,
:created_at
,
:total_time
,
:url
,
:author
,
:state
)
expect
(
subject
).
to
include
(
:title
,
:iid
,
:created_at
,
:total_time
,
:url
,
:author
,
:state
)
end
end
end
end
end
end
spec/serializers/analytics_stage_serializer_spec.rb
View file @
42e3f0fd
require
'spec_helper'
require
'spec_helper'
describe
AnalyticsStageSerializer
do
describe
AnalyticsStageSerializer
do
let
(
:serializer
)
do
subject
do
described_class
described_class
.
new
.
represent
(
resource
)
.
new
.
represent
(
resource
)
end
end
let
(
:json
)
{
serializer
.
as_json
}
let
(
:resource
)
do
let
(
:resource
)
{
Gitlab
::
CycleAnalytics
::
CodeStage
.
new
(
project:
double
,
options:
{})
}
Gitlab
::
CycleAnalytics
::
CodeStage
.
new
(
project:
double
,
options:
{})
end
before
do
before
do
allow_any_instance_of
(
Gitlab
::
CycleAnalytics
::
BaseStage
).
to
receive
(
:median
).
and_return
(
1.12
)
allow_any_instance_of
(
Gitlab
::
CycleAnalytics
::
BaseStage
).
to
receive
(
:median
).
and_return
(
1.12
)
...
@@ -15,10 +15,10 @@ describe AnalyticsStageSerializer do
...
@@ -15,10 +15,10 @@ describe AnalyticsStageSerializer do
end
end
it
'it generates payload for single object'
do
it
'it generates payload for single object'
do
expect
(
json
).
to
be_kind_of
Hash
expect
(
subject
).
to
be_kind_of
Hash
end
end
it
'contains important elements of AnalyticsStage'
do
it
'contains important elements of AnalyticsStage'
do
expect
(
json
).
to
include
(
:title
,
:description
,
:value
)
expect
(
subject
).
to
include
(
:title
,
:description
,
:value
)
end
end
end
end
spec/serializers/analytics_summary_serializer_spec.rb
View file @
42e3f0fd
require
'spec_helper'
require
'spec_helper'
describe
AnalyticsSummarySerializer
do
describe
AnalyticsSummarySerializer
do
let
(
:serializer
)
do
subject
do
described_class
described_class
.
new
.
represent
(
resource
)
.
new
.
represent
(
resource
)
end
end
let
(
:json
)
{
serializer
.
as_json
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:resource
)
do
let
(
:resource
)
do
Gitlab
::
CycleAnalytics
::
Summary
::
Issue
.
new
(
project:
double
,
Gitlab
::
CycleAnalytics
::
Summary
::
Issue
from:
1
.
day
.
ago
,
.
new
(
project:
double
,
from:
1
.
day
.
ago
,
current_user:
user
)
current_user:
user
)
end
end
before
do
before
do
allow_any_instance_of
(
Gitlab
::
CycleAnalytics
::
Summary
::
Issue
).
to
receive
(
:value
).
and_return
(
1.12
)
allow_any_instance_of
(
Gitlab
::
CycleAnalytics
::
Summary
::
Issue
)
.
to
receive
(
:value
).
and_return
(
1.12
)
end
end
it
'it generates payload for single object'
do
it
'it generates payload for single object'
do
expect
(
json
).
to
be_kind_of
Hash
expect
(
subject
).
to
be_kind_of
Hash
end
end
it
'contains important elements of AnalyticsStage'
do
it
'contains important elements of AnalyticsStage'
do
expect
(
json
).
to
include
(
:title
,
:value
)
expect
(
subject
).
to
include
(
:title
,
:value
)
end
end
end
end
spec/serializers/environment_serializer_spec.rb
View file @
42e3f0fd
require
'spec_helper'
require
'spec_helper'
describe
EnvironmentSerializer
do
describe
EnvironmentSerializer
do
let
(
:serializer
)
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:json
)
do
described_class
described_class
.
new
(
user:
user
,
project:
project
)
.
new
(
user:
user
,
project:
project
)
.
represent
(
resource
)
.
represent
(
resource
)
end
end
let
(
:json
)
{
serializer
.
as_json
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
context
'when there is a single object provided'
do
context
'when there is a single object provided'
do
before
do
before
do
create
(
:ci_build
,
:manual
,
name:
'manual1'
,
create
(
:ci_build
,
:manual
,
name:
'manual1'
,
...
...
spec/serializers/pipeline_serializer_spec.rb
View file @
42e3f0fd
...
@@ -7,11 +7,7 @@ describe PipelineSerializer do
...
@@ -7,11 +7,7 @@ describe PipelineSerializer do
described_class
.
new
(
user:
user
)
described_class
.
new
(
user:
user
)
end
end
let
(
:entity
)
do
subject
{
serializer
.
represent
(
resource
)
}
serializer
.
represent
(
resource
)
end
subject
{
entity
.
as_json
}
describe
'#represent'
do
describe
'#represent'
do
context
'when used without pagination'
do
context
'when used without pagination'
do
...
...
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