summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-27 22:32:36 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-17 12:58:57 -0300
commitb23683b00b4bccad3b6f29d722b9e45a7264c1bd (patch)
tree15f14e1a27d20d86f9bba931b338581ead533019
parent279361fa16c52011ee0f565c79a47012fad9b03f (diff)
downloadgitlab-ce-b23683b00b4bccad3b6f29d722b9e45a7264c1bd.tar.gz
Add service to remove a list from board
-rw-r--r--app/services/boards/lists/destroy_service.rb34
-rw-r--r--spec/services/boards/lists/destroy_service_spec.rb30
2 files changed, 64 insertions, 0 deletions
diff --git a/app/services/boards/lists/destroy_service.rb b/app/services/boards/lists/destroy_service.rb
new file mode 100644
index 00000000000..0913a898abd
--- /dev/null
+++ b/app/services/boards/lists/destroy_service.rb
@@ -0,0 +1,34 @@
+module Boards
+ module Lists
+ class DestroyService
+ def initialize(project, params = {})
+ @board = project.board
+ @params = params.dup
+ end
+
+ def execute
+ list.with_lock do
+ reorder_higher_lists
+ remove_list
+ end
+ end
+
+ private
+
+ attr_reader :board, :params
+
+ def list
+ @list ||= board.lists.find(params[:list_id])
+ end
+
+ def reorder_higher_lists
+ board.lists.where('position > ?', list.position)
+ .update_all('position = position - 1')
+ end
+
+ def remove_list
+ list.destroy
+ end
+ end
+ end
+end
diff --git a/spec/services/boards/lists/destroy_service_spec.rb b/spec/services/boards/lists/destroy_service_spec.rb
new file mode 100644
index 00000000000..5fe9fa51407
--- /dev/null
+++ b/spec/services/boards/lists/destroy_service_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe Boards::Lists::DestroyService, services: true do
+ describe '#execute' do
+ let(:project) { create(:project_with_board) }
+ let(:board) { project.board }
+
+ it 'removes list from board' do
+ list = create(:list, board: board)
+ service = described_class.new(project, list_id: list.id)
+
+ expect { service.execute }.to change(board.lists, :count).by(-1)
+ end
+
+ it 'decrements position of higher lists' do
+ list1 = create(:list, board: board, position: 1)
+ list2 = create(:list, board: board, position: 2)
+ list3 = create(:list, board: board, position: 3)
+ list4 = create(:list, board: board, position: 4)
+ list5 = create(:list, board: board, position: 5)
+
+ described_class.new(project, list_id: list2.id).execute
+
+ expect(list1.reload.position).to eq 1
+ expect(list3.reload.position).to eq 2
+ expect(list4.reload.position).to eq 3
+ expect(list5.reload.position).to eq 4
+ end
+ end
+end