diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-08 16:49:09 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-17 12:58:59 -0300 |
commit | 6113767045971abd3a279705f481c8e712660c88 (patch) | |
tree | d06f0974c2d5f42bcba0e765a02287693108215d | |
parent | 68cfdba7018172d502d4b98aad02e86d22a6a401 (diff) | |
download | gitlab-ce-6113767045971abd3a279705f481c8e712660c88.tar.gz |
Add an endpoint to generate the default lists for a board
-rw-r--r-- | app/controllers/projects/board_lists_controller.rb | 10 | ||||
-rw-r--r-- | config/routes.rb | 4 | ||||
-rw-r--r-- | spec/controllers/projects/board_lists_controller_spec.rb | 32 |
3 files changed, 46 insertions, 0 deletions
diff --git a/app/controllers/projects/board_lists_controller.rb b/app/controllers/projects/board_lists_controller.rb index 738c06c57ef..63daba09e6a 100644 --- a/app/controllers/projects/board_lists_controller.rb +++ b/app/controllers/projects/board_lists_controller.rb @@ -33,6 +33,16 @@ class Projects::BoardListsController < Projects::ApplicationController end end + def generate + service = Boards::Lists::GenerateService.new(project, current_user) + + if service.execute + render json: project.board.lists.label.as_json(only: [:id, :list_type, :position], methods: [:title], include: { label: { only: [:id, :title, :color] } }) + else + head :unprocessable_entity + end + end + private def list_params diff --git a/config/routes.rb b/config/routes.rb index 244f0d49ab9..3b17ed612bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -860,6 +860,10 @@ Rails.application.routes.draw do resources :issues, only: [:update], controller: :board_issues resources :lists, only: [:create, :update, :destroy], controller: :board_lists do + collection do + post :generate + end + resources :issues, only: [:index], controller: :board_issues end end diff --git a/spec/controllers/projects/board_lists_controller_spec.rb b/spec/controllers/projects/board_lists_controller_spec.rb index cf8801ca4f6..c37ced574a9 100644 --- a/spec/controllers/projects/board_lists_controller_spec.rb +++ b/spec/controllers/projects/board_lists_controller_spec.rb @@ -119,4 +119,36 @@ describe Projects::BoardListsController do format: :json end end + + describe 'POST #generate' do + context 'when board lists is empty' do + it 'returns a successful 200 response' do + generate_default_board_lists + + expect(response).to have_http_status(200) + end + + it 'returns the defaults lists' do + generate_default_board_lists + + expect(response).to match_response_schema('list', array: true) + end + end + + context 'when board lists is not empty' do + it 'returns a unprocessable entity 422 response' do + create(:list, board: board) + + generate_default_board_lists + + expect(response).to have_http_status(422) + end + end + + def generate_default_board_lists + post :generate, namespace_id: project.namespace.to_param, + project_id: project.to_param, + format: :json + end + end end |