Add endpoint to allow users to remove lists

This commit is contained in:
Douglas Barbosa Alexandre 2016-08-01 18:44:33 -03:00
parent aa97c0fd12
commit 547d218e6b
3 changed files with 47 additions and 1 deletions

View file

@ -25,6 +25,18 @@ class Projects::BoardListsController < Projects::ApplicationController
end
end
def destroy
service = Boards::Lists::DestroyService.new(project, params)
respond_to do |format|
if service.execute
format.json { head :ok }
else
format.json { head :unprocessable_entity }
end
end
end
private
def record_not_found(exception)

View file

@ -857,7 +857,7 @@ Rails.application.routes.draw do
end
resource :board, only: [:show] do
resources :lists, only: [:create, :update], controller: :board_lists
resources :lists, only: [:create, :update, :destroy], controller: :board_lists
end
resources :todos, only: [:create]

View file

@ -97,5 +97,39 @@ describe Projects::BoardListsController do
end
end
end
describe 'DELETE #destroy' do
context 'with valid list id' do
let!(:planning) { create(:list, board: project.board, position: 1) }
it 'returns a successful 200 response' do
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: planning.to_param,
format: :json
expect(response).to have_http_status(200)
end
it 'removes list from board' do
expect do
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: planning.to_param,
format: :json
end.to change(project.board.lists, :size).by(-1)
end
end
context 'with invalid list id' do
it 'returns a not found 404 response' do
delete :destroy, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: 999,
format: :json
expect(response).to have_http_status(404)
end
end
end
end