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
27dd0b8e
Commit
27dd0b8e
authored
Jun 06, 2019
by
charlieablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use serialization for project boards
- Add serializers and Grape::Entity - Replace to_json - Add specs
parent
7468ed5f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
1 deletion
+72
-1
app/controllers/concerns/boards_actions.rb
app/controllers/concerns/boards_actions.rb
+8
-0
app/controllers/concerns/boards_responses.rb
app/controllers/concerns/boards_responses.rb
+5
-1
app/serializers/board_serializer.rb
app/serializers/board_serializer.rb
+5
-0
app/serializers/board_simple_entity.rb
app/serializers/board_simple_entity.rb
+5
-0
changelogs/unreleased/ce-3861-use-serializers-for-project-group-boards.yml
...ased/ce-3861-use-serializers-for-project-group-boards.yml
+6
-0
spec/controllers/concerns/boards_responses_spec.rb
spec/controllers/concerns/boards_responses_spec.rb
+23
-0
spec/serializers/board_serializer_spec.rb
spec/serializers/board_serializer_spec.rb
+20
-0
No files found.
app/controllers/concerns/boards_actions.rb
View file @
27dd0b8e
...
@@ -35,4 +35,12 @@ module BoardsActions
...
@@ -35,4 +35,12 @@ module BoardsActions
boards
.
find
(
params
[
:id
])
boards
.
find
(
params
[
:id
])
end
end
end
end
def
serializer
BoardSerializer
.
new
(
current_user:
current_user
)
end
def
serialize_as_json
(
resource
)
serializer
.
represent
(
resource
,
serializer:
'board'
,
include_full_project_path:
board
.
group_board?
)
end
end
end
app/controllers/concerns/boards_responses.rb
View file @
27dd0b8e
...
@@ -69,7 +69,7 @@ module BoardsResponses
...
@@ -69,7 +69,7 @@ module BoardsResponses
end
end
def
serialize_as_json
(
resource
)
def
serialize_as_json
(
resource
)
resource
.
as_json
(
only:
[
:id
]
)
serializer
.
represent
(
resource
)
end
end
def
respond_with
(
resource
)
def
respond_with
(
resource
)
...
@@ -80,4 +80,8 @@ module BoardsResponses
...
@@ -80,4 +80,8 @@ module BoardsResponses
end
end
end
end
end
end
def
serializer
BoardSerializer
.
new
end
end
end
app/serializers/board_serializer.rb
0 → 100644
View file @
27dd0b8e
# frozen_string_literal: true
class
BoardSerializer
<
BaseSerializer
entity
BoardSimpleEntity
end
app/serializers/board_simple_entity.rb
0 → 100644
View file @
27dd0b8e
# frozen_string_literal: true
class
BoardSimpleEntity
<
Grape
::
Entity
expose
:id
end
changelogs/unreleased/ce-3861-use-serializers-for-project-group-boards.yml
0 → 100644
View file @
27dd0b8e
---
title
:
Refactor Board JSON serialization to use Grape::Entity instead of manual serialization
(to_json)
merge_request
:
author
:
type
:
changed
spec/controllers/concerns/boards_responses_spec.rb
0 → 100644
View file @
27dd0b8e
# frozen_string_literal: true
require
'spec_helper'
describe
BoardsResponses
do
let
(
:controller_class
)
do
Class
.
new
do
include
BoardsResponses
end
end
subject
(
:controller
)
{
controller_class
.
new
}
describe
'#serialize_as_json'
do
let!
(
:board
)
{
create
(
:board
)
}
it
'serializes properly'
do
expected
=
{
id:
board
.
id
}
expect
(
subject
.
serialize_as_json
(
board
).
to_h
).
to
include
(
expected
)
end
end
end
spec/serializers/board_serializer_spec.rb
0 → 100644
View file @
27dd0b8e
# frozen_string_literal: true
require
'spec_helper'
describe
BoardSerializer
do
let
(
:resource
)
{
create
(
:board
)
}
let
(
:json_entity
)
do
described_class
.
new
.
represent
(
resource
,
serializer:
serializer
)
.
with_indifferent_access
end
context
'serialization'
do
let
(
:serializer
)
{
'board'
}
it
'matches issue_sidebar json schema'
do
expect
(
json_entity
).
to
match_schema
(
'board'
)
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