Projects::BoardsController#show returns a list of board lists

parent bddb2f93
class Projects::BoardsController < Projects::ApplicationController class Projects::BoardsController < Projects::ApplicationController
def show def show
Boards::CreateService.new(project).execute board = Boards::CreateService.new(project).execute
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: board.lists.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :color] } }) }
end end
end end
end end
...@@ -10,15 +10,42 @@ describe Projects::BoardsController do ...@@ -10,15 +10,42 @@ describe Projects::BoardsController do
end end
describe 'GET #show' do describe 'GET #show' do
it 'creates a new board when project does not have one' do context 'when project does not have a board' do
expect { get :show, namespace_id: project.namespace.to_param, project_id: project.to_param }.to change(Board, :count).by(1) it 'creates a new board' do
expect { get :show, namespace_id: project.namespace.to_param, project_id: project.to_param }.to change(Board, :count).by(1)
end
end end
it 'renders HTML template' do context 'when format is HTML' do
get :show, namespace_id: project.namespace.to_param, project_id: project.to_param it 'renders HTML template' do
get :show, namespace_id: project.namespace.to_param, project_id: project.to_param
expect(response).to render_template :show expect(response).to render_template :show
expect(response.content_type).to eq 'text/html' expect(response.content_type).to eq 'text/html'
end
end
context 'when format is JSON' do
it 'returns a successful 200 response' do
get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, format: :json
expect(response).to have_http_status(200)
expect(response.content_type).to eq 'application/json'
end
it 'returns a list of board lists' do
board = project.create_board
create(:backlog_list, board: board)
create(:list, board: board)
create(:done_list, board: board)
get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, format: :json
parsed_response = JSON.parse(response.body)
expect(response).to match_response_schema('list', array: true)
expect(parsed_response.length).to eq 3
end
end end
end end
end end
{
"type": "object",
"required" : [
"id",
"list_type",
"title",
"position"
],
"properties" : {
"id": { "type": "integer" },
"list_type": {
"type": "string",
"enum": ["backlog", "label", "done"]
},
"label": {
"type": ["object"],
"required": [
"id",
"color",
"title"
],
"properties": {
"id": { "type": "integer" },
"color": {
"type": "string",
"pattern": "^#[0-9A-Fa-f]{3}{1,2}+$"
},
"title": { "type": "string" }
}
},
"title": { "type": "string" },
"position": { "type": ["integer", "null"] }
},
"additionalProperties": false
}
RSpec::Matchers.define :match_response_schema do |schema, options = {}|
match do |response|
schema_directory = "#{Dir.pwd}/spec/fixtures/api/schemas"
schema_path = "#{schema_directory}/#{schema}.json"
list = options.fetch(:array, false)
JSON::Validator.validate!(schema_path, response.body, list: list)
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