Commit 3db2e15b authored by Stan Hu's avatar Stan Hu

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
parents 40d309cc 0c29aa0d
...@@ -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
...@@ -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).as_json
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
# frozen_string_literal: true
class BoardSerializer < BaseSerializer
entity BoardSimpleEntity
end
# frozen_string_literal: true
class BoardSimpleEntity < Grape::Entity
expose :id
end
# 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
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment