Merge branch 'ce-3861-use-serializers-for-project-group-boards' into 'master'
Use serialization for project boards See merge request gitlab-org/gitlab-ce!29263
This commit is contained in:
commit
3db2e15b72
6 changed files with 66 additions and 1 deletions
|
@ -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
|
||||||
|
|
|
@ -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).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_with(resource)
|
def respond_with(resource)
|
||||||
|
@ -80,4 +80,8 @@ module BoardsResponses
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def serializer
|
||||||
|
BoardSerializer.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
5
app/serializers/board_serializer.rb
Normal file
5
app/serializers/board_serializer.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class BoardSerializer < BaseSerializer
|
||||||
|
entity BoardSimpleEntity
|
||||||
|
end
|
5
app/serializers/board_simple_entity.rb
Normal file
5
app/serializers/board_simple_entity.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class BoardSimpleEntity < Grape::Entity
|
||||||
|
expose :id
|
||||||
|
end
|
23
spec/controllers/concerns/boards_responses_spec.rb
Normal file
23
spec/controllers/concerns/boards_responses_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# 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 include(expected)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
20
spec/serializers/board_serializer_spec.rb
Normal file
20
spec/serializers/board_serializer_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# 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
|
Loading…
Reference in a new issue