From 5ef567e33df9f4562f56fdbf60329c027dbfa913 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 28 Jul 2016 01:54:13 -0300 Subject: [PATCH] Does not allow Backlog/Done lists to be removed --- app/services/boards/lists/destroy_service.rb | 2 + spec/factories/lists.rb | 12 +++++ .../boards/lists/destroy_service_spec.rb | 46 +++++++++++++------ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/app/services/boards/lists/destroy_service.rb b/app/services/boards/lists/destroy_service.rb index 0913a898abd..ba097942aa6 100644 --- a/app/services/boards/lists/destroy_service.rb +++ b/app/services/boards/lists/destroy_service.rb @@ -7,6 +7,8 @@ def initialize(project, params = {}) end def execute + return false unless list.label? + list.with_lock do reorder_higher_lists remove_list diff --git a/spec/factories/lists.rb b/spec/factories/lists.rb index 4e493da41a0..bef161d2a7e 100644 --- a/spec/factories/lists.rb +++ b/spec/factories/lists.rb @@ -4,4 +4,16 @@ label sequence(:position) 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 diff --git a/spec/services/boards/lists/destroy_service_spec.rb b/spec/services/boards/lists/destroy_service_spec.rb index 5fe9fa51407..85cc3a0bc67 100644 --- a/spec/services/boards/lists/destroy_service_spec.rb +++ b/spec/services/boards/lists/destroy_service_spec.rb @@ -5,26 +5,42 @@ 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) + context 'when list type is label' do + it 'removes list from board' do + 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 - 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) + it 'does not remove list from board when list type is backlog' do + list = create(:backlog_list, board: board) + service = described_class.new(project, list_id: list.id) + + expect { service.execute }.not_to change(board.lists, :count) + 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(list3.reload.position).to eq 2 - expect(list4.reload.position).to eq 3 - expect(list5.reload.position).to eq 4 + expect { service.execute }.not_to change(board.lists, :count) end end end -- GitLab