BigW Consortium Gitlab

Add endpoint to allow users to create a new board list

parent e1998844
class Projects::BoardListsController < Projects::ApplicationController
def create
list = Boards::Lists::CreateService.new(project, list_params).execute
respond_to do |format|
if list.valid?
format.json { render json: list.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :color] } }) }
else
format.json { render json: list.errors, status: :unprocessable_entity }
end
end
end
private
def list_params
params.require(:list).permit(:label_id)
end
end
......@@ -856,7 +856,9 @@ Rails.application.routes.draw do
end
end
resource :board, only: [:show]
resource :board, only: [:show] do
resources :lists, only: [:create], controller: :board_lists
end
resources :todos, only: [:create]
......
require 'spec_helper'
describe Projects::BoardListsController do
let(:project) { create(:project_with_board) }
let(:user) { create(:user) }
before do
project.team << [user, :master]
sign_in(user)
end
describe 'POST #create' do
context 'with valid params' do
let(:label) { create(:label, project: project, name: 'Development') }
it 'returns a successful 200 response' do
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
list: { label_id: label.id },
format: :json
expect(response).to have_http_status(200)
end
it 'returns the created list' do
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
list: { label_id: label.id },
format: :json
expect(response).to match_response_schema('list')
end
end
context 'with invalid params' do
it 'returns an error' do
post :create, namespace_id: project.namespace.to_param,
project_id: project.to_param,
list: { label_id: nil },
format: :json
parsed_response = JSON.parse(response.body)
expect(parsed_response['label']).to contain_exactly "can't be blank"
expect(response).to have_http_status(422)
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