diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-07-29 01:26:16 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-08-17 18:58:57 +0300 |
commit | b07c5f23b8761ae87d29ded1a69b14ae6393443a (patch) | |
tree | ec6d9812ae818c282480ef930c971462a203560f /spec/services/boards | |
parent | 35420cec0bf511af662e09cbd8664720c58fa187 (diff) |
Order board lists by list_type, and position
Diffstat (limited to 'spec/services/boards')
-rw-r--r-- | spec/services/boards/lists/create_service_spec.rb | 31 | ||||
-rw-r--r-- | spec/services/boards/lists/destroy_service_spec.rb | 24 | ||||
-rw-r--r-- | spec/services/boards/lists/move_service_spec.rb | 71 |
3 files changed, 71 insertions, 55 deletions
diff --git a/spec/services/boards/lists/create_service_spec.rb b/spec/services/boards/lists/create_service_spec.rb index 09cef364a3b..0e8190794a0 100644 --- a/spec/services/boards/lists/create_service_spec.rb +++ b/spec/services/boards/lists/create_service_spec.rb @@ -9,16 +9,16 @@ describe Boards::Lists::CreateService, services: true do subject(:service) { described_class.new(project, label_id: label.id) } context 'when board lists is empty' do - it 'creates a new list at begginning of the list' do + it 'creates a new list at beginning of the list' do list = service.execute - expect(list.position).to eq 0 + expect(list.position).to eq 1 end end - context 'when board lists has a backlog list' do - it 'creates a new list at end of the list' do - create(:backlog_list, board: board, position: 0) + context 'when board lists has only a backlog list' do + it 'creates a new list at beginning of the list' do + create(:backlog_list, board: board) list = service.execute @@ -26,9 +26,10 @@ describe Boards::Lists::CreateService, services: true do end end - context 'when board lists are only labels lists' do - it 'creates a new list at end of the list' do - create_list(:label_list, 2, board: board) + context 'when board lists has only labels lists' do + it 'creates a new list at end of the lists' do + create(:label_list, board: board, position: 1) + create(:label_list, board: board, position: 2) list = described_class.new(project, label_id: label.id).execute @@ -36,18 +37,16 @@ describe Boards::Lists::CreateService, services: true do end end - context 'when board lists has a done list' do - it 'creates a new list before' do - list1 = create(:backlog_list, board: board, position: 1) - list2 = create(:label_list, board: board, position: 2) - list3 = create(:done_list, board: board, position: 3) + context 'when board lists has backlog, label and done lists' do + it 'creates a new list at end of the label lists' do + create(:backlog_list, board: board) + create(:done_list, board: board) + list1 = create(:label_list, board: board, position: 1) - list = described_class.new(project, label_id: label.id).execute + list2 = described_class.new(project, label_id: label.id).execute - expect(list.position).to eq 3 expect(list1.reload.position).to eq 1 expect(list2.reload.position).to eq 2 - expect(list3.reload.position).to eq 4 end end end diff --git a/spec/services/boards/lists/destroy_service_spec.rb b/spec/services/boards/lists/destroy_service_spec.rb index 85cc3a0bc67..4d50bd2d123 100644 --- a/spec/services/boards/lists/destroy_service_spec.rb +++ b/spec/services/boards/lists/destroy_service_spec.rb @@ -14,18 +14,18 @@ describe Boards::Lists::DestroyService, services: true do 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(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 + backlog = create(:backlog_list, board: board) + development = create(:label_list, board: board, position: 1) + review = create(:label_list, board: board, position: 2) + staging = create(:label_list, board: board, position: 3) + done = create(:done_list, board: board) + + described_class.new(project, list_id: development.id).execute + + expect(backlog.reload.position).to be_nil + expect(review.reload.position).to eq 1 + expect(staging.reload.position).to eq 2 + expect(done.reload.position).to be_nil end end diff --git a/spec/services/boards/lists/move_service_spec.rb b/spec/services/boards/lists/move_service_spec.rb index 072087a0e05..97de502e069 100644 --- a/spec/services/boards/lists/move_service_spec.rb +++ b/spec/services/boards/lists/move_service_spec.rb @@ -4,81 +4,98 @@ describe Boards::Lists::MoveService, services: true do describe '#execute' do let(:project) { create(:project_with_board) } let(:board) { project.board } - let!(:list1) { create(:backlog_list, board: board, position: 1) } - let!(:list2) { create(:label_list, board: board, position: 2) } - let!(:list3) { create(:label_list, board: board, position: 3) } - let!(:list4) { create(:label_list, board: board, position: 4) } - let!(:list5) { create(:label_list, board: board, position: 5) } - let!(:list6) { create(:done_list, board: board, position: 6) } + + let!(:backlog) { create(:backlog_list, board: board) } + let!(:planning) { create(:label_list, board: board, position: 1) } + let!(:development) { create(:label_list, board: board, position: 2) } + let!(:review) { create(:label_list, board: board, position: 3) } + let!(:staging) { create(:label_list, board: board, position: 4) } + let!(:done) { create(:done_list, board: board) } context 'when list type is set to label' do it 'keeps position of lists when new position is nil' do - service = described_class.new(project, { list_id: list2.id, position: nil }) + service = described_class.new(project, { list_id: planning.id, position: nil }) service.execute - expect(positions_of_lists).to eq [1, 2, 3, 4, 5, 6] + expect(current_list_positions).to eq [1, 2, 3, 4] end it 'keeps position of lists when new positon is equal to old position' do - service = described_class.new(project, { list_id: list2.id, position: 2 }) + service = described_class.new(project, { list_id: planning.id, position: 1 }) + + service.execute + + expect(current_list_positions).to eq [1, 2, 3, 4] + end + + it 'keeps position of lists when new positon is negative' do + service = described_class.new(project, { list_id: planning.id, position: -1 }) + + service.execute + + expect(current_list_positions).to eq [1, 2, 3, 4] + end + + it 'keeps position of lists when new positon is greater than number of labels lists' do + service = described_class.new(project, { list_id: planning.id, position: 6 }) service.execute - expect(positions_of_lists).to eq [1, 2, 3, 4, 5, 6] + expect(current_list_positions).to eq [1, 2, 3, 4] end - it 'keeps position of lists when new positon is equal to first position' do - service = described_class.new(project, { list_id: list3.id, position: 1 }) + it 'increments position of intermediate lists when new positon is equal to first position' do + service = described_class.new(project, { list_id: staging.id, position: 1 }) service.execute - expect(positions_of_lists).to eq [1, 2, 3, 4, 5, 6] + expect(current_list_positions).to eq [2, 3, 4, 1] end - it 'keeps position of lists when new positon is equal to last position' do - service = described_class.new(project, { list_id: list3.id, position: 6 }) + it 'decrements position of intermediate lists when new positon is equal to last position' do + service = described_class.new(project, { list_id: planning.id, position: 4 }) service.execute - expect(positions_of_lists).to eq [1, 2, 3, 4, 5, 6] + expect(current_list_positions).to eq [4, 1, 2, 3] end it 'decrements position of intermediate lists when new position is greater than old position' do - service = described_class.new(project, { list_id: list2.id, position: 5 }) + service = described_class.new(project, { list_id: planning.id, position: 3 }) service.execute - expect(positions_of_lists).to eq [1, 5, 2, 3, 4, 6] + expect(current_list_positions).to eq [3, 1, 2, 4] end - it 'increments position of intermediate lists when when new position is lower than old position' do - service = described_class.new(project, { list_id: list5.id, position: 2 }) + it 'increments position of intermediate lists when new position is lower than old position' do + service = described_class.new(project, { list_id: staging.id, position: 2 }) service.execute - expect(positions_of_lists).to eq [1, 3, 4, 5, 2, 6] + expect(current_list_positions).to eq [1, 3, 4, 2] end end it 'keeps position of lists when list type is backlog' do - service = described_class.new(project, { list_id: list1.id, position: 2 }) + service = described_class.new(project, { list_id: backlog.id, position: 2 }) service.execute - expect(positions_of_lists).to eq [1, 2, 3, 4, 5, 6] + expect(current_list_positions).to eq [1, 2, 3, 4] end it 'keeps position of lists when list type is done' do - service = described_class.new(project, { list_id: list6.id, position: 2 }) + service = described_class.new(project, { list_id: done.id, position: 2 }) service.execute - expect(positions_of_lists).to eq [1, 2, 3, 4, 5, 6] + expect(current_list_positions).to eq [1, 2, 3, 4] end end - def positions_of_lists - (1..6).map { |index| send("list#{index}").reload.position } + def current_list_positions + [planning, development, review, staging].map { |list| list.reload.position } end end |