Split and prepend CurrentBoardEntity

(cherry picked from commit 1e8bdd01bff96122fe80c51fa8f024f18675b58b)
This commit is contained in:
Winnie Hellmann 2019-07-12 06:31:17 +00:00 committed by Jan Provaznik
parent 4c6bdd23b3
commit 2e6225538f
5 changed files with 46 additions and 3 deletions

View file

@ -99,7 +99,11 @@ module BoardsHelper
recent_project_boards_path(@project) if current_board_parent.is_a?(Project)
end
def serializer
CurrentBoardSerializer.new
end
def current_board_json
board.to_json
serializer.represent(board).as_json
end
end

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
class CurrentBoardEntity < Grape::Entity
expose :id
expose :name
end

View file

@ -0,0 +1,5 @@
# frozen_string_literal: true
class CurrentBoardSerializer < BaseSerializer
entity CurrentBoardEntity
end

View file

@ -0,0 +1,16 @@
{
"type": "object",
"allOf": [
{ "$ref": "board.json" },
{
"required" : [
"id",
"name"
],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" }
}
}
]
}

View file

@ -1,10 +1,12 @@
require 'spec_helper'
describe BoardsHelper do
set(:project) { create(:project) }
describe '#build_issue_link_base' do
context 'project board' do
it 'returns correct path for project board' do
@project = create(:project)
@project = project
@board = create(:board, project: @project)
expect(build_issue_link_base).to eq("/#{@project.namespace.path}/#{@project.path}/issues")
@ -31,7 +33,6 @@ describe BoardsHelper do
describe '#board_data' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:board) { create(:board, project: project) }
before do
@ -46,4 +47,15 @@ describe BoardsHelper do
expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(board))
end
end
describe '#current_board_json' do
let(:board_json) { helper.current_board_json }
it 'can serialise with a basic set of attributes' do
board = create(:board, project: project)
assign(:board, board)
expect(board_json).to match_schema('current-board')
end
end
end