Commit 2e622553 authored by Winnie Hellmann's avatar Winnie Hellmann Committed by Jan Provaznik

Split and prepend CurrentBoardEntity

(cherry picked from commit 1e8bdd01bff96122fe80c51fa8f024f18675b58b)
parent 4c6bdd23
...@@ -99,7 +99,11 @@ module BoardsHelper ...@@ -99,7 +99,11 @@ module BoardsHelper
recent_project_boards_path(@project) if current_board_parent.is_a?(Project) recent_project_boards_path(@project) if current_board_parent.is_a?(Project)
end end
def serializer
CurrentBoardSerializer.new
end
def current_board_json def current_board_json
board.to_json serializer.represent(board).as_json
end end
end end
# frozen_string_literal: true
class CurrentBoardEntity < Grape::Entity
expose :id
expose :name
end
# frozen_string_literal: true
class CurrentBoardSerializer < BaseSerializer
entity CurrentBoardEntity
end
{
"type": "object",
"allOf": [
{ "$ref": "board.json" },
{
"required" : [
"id",
"name"
],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" }
}
}
]
}
require 'spec_helper' require 'spec_helper'
describe BoardsHelper do describe BoardsHelper do
set(:project) { create(:project) }
describe '#build_issue_link_base' do describe '#build_issue_link_base' do
context 'project board' do context 'project board' do
it 'returns correct path for project board' do it 'returns correct path for project board' do
@project = create(:project) @project = project
@board = create(:board, project: @project) @board = create(:board, project: @project)
expect(build_issue_link_base).to eq("/#{@project.namespace.path}/#{@project.path}/issues") expect(build_issue_link_base).to eq("/#{@project.namespace.path}/#{@project.path}/issues")
...@@ -31,7 +33,6 @@ describe BoardsHelper do ...@@ -31,7 +33,6 @@ describe BoardsHelper do
describe '#board_data' do describe '#board_data' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) }
let(:board) { create(:board, project: project) } let(:board) { create(:board, project: project) }
before do before do
...@@ -46,4 +47,15 @@ describe BoardsHelper do ...@@ -46,4 +47,15 @@ describe BoardsHelper do
expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(board)) expect(helper.board_data[:lists_endpoint]).to eq(board_lists_path(board))
end end
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 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