Does not allow Backlog/Done lists to be removed

parent 4180a15c
...@@ -7,6 +7,8 @@ module Boards ...@@ -7,6 +7,8 @@ module Boards
end end
def execute def execute
return false unless list.label?
list.with_lock do list.with_lock do
reorder_higher_lists reorder_higher_lists
remove_list remove_list
......
...@@ -4,4 +4,16 @@ FactoryGirl.define do ...@@ -4,4 +4,16 @@ FactoryGirl.define do
label label
sequence(:position) sequence(:position)
end end
factory :backlog_list, parent: :list do
list_type :backlog
end
factory :label_list, parent: :list do
list_type :label
end
factory :done_list, parent: :list do
list_type :done
end
end end
...@@ -5,26 +5,42 @@ describe Boards::Lists::DestroyService, services: true do ...@@ -5,26 +5,42 @@ describe Boards::Lists::DestroyService, services: true do
let(:project) { create(:project_with_board) } let(:project) { create(:project_with_board) }
let(:board) { project.board } let(:board) { project.board }
it 'removes list from board' do context 'when list type is label' do
list = create(:list, board: board) it 'removes list from board' do
service = described_class.new(project, list_id: list.id) list = create(:label_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(:backlog_list, board: board, position: 1)
list2 = create(:label_list, board: board, position: 2)
list3 = create(:label_list, board: board, position: 3)
list4 = create(:label_list, board: board, position: 4)
list5 = create(:done_list, board: board, position: 5)
described_class.new(project, list_id: list2.id).execute
expect { service.execute }.to change(board.lists, :count).by(-1) 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
it 'decrements position of higher lists' do it 'does not remove list from board when list type is backlog' do
list1 = create(:list, board: board, position: 1) list = create(:backlog_list, board: board)
list2 = create(:list, board: board, position: 2) service = described_class.new(project, list_id: list.id)
list3 = create(:list, board: board, position: 3)
list4 = create(:list, board: board, position: 4) expect { service.execute }.not_to change(board.lists, :count)
list5 = create(:list, board: board, position: 5) end
described_class.new(project, list_id: list2.id).execute it 'does not remove list from board when list type is done' do
list = create(:done_list, board: board)
service = described_class.new(project, list_id: list.id)
expect(list1.reload.position).to eq 1 expect { service.execute }.not_to change(board.lists, :count)
expect(list3.reload.position).to eq 2
expect(list4.reload.position).to eq 3
expect(list5.reload.position).to eq 4
end end
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