summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-27 20:33:22 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-17 12:58:57 -0300
commit279361fa16c52011ee0f565c79a47012fad9b03f (patch)
tree309f93bd1073a2f3307c2fd1f6d14ef4ea03ee63 /spec
parent247e11c94865b429c400fd9f0d1730c13b0b0c35 (diff)
downloadgitlab-ce-279361fa16c52011ee0f565c79a47012fad9b03f.tar.gz
Add service to move board lists
Diffstat (limited to 'spec')
-rw-r--r--spec/services/boards/lists/move_service_spec.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/spec/services/boards/lists/move_service_spec.rb b/spec/services/boards/lists/move_service_spec.rb
new file mode 100644
index 00000000000..e61914dba62
--- /dev/null
+++ b/spec/services/boards/lists/move_service_spec.rb
@@ -0,0 +1,76 @@
+require 'spec_helper'
+
+describe Boards::Lists::MoveService, services: true do
+ describe '#execute' do
+ let(:project) { create(:project_with_board) }
+ let(:board) { project.board }
+
+ it 'keeps position of lists when new position is nil' 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)
+
+ service = described_class.new(project, { list_id: list2.id, position: nil })
+
+ expect(service.execute).to eq false
+ expect(list1.reload.position).to eq 1
+ expect(list2.reload.position).to eq 2
+ expect(list3.reload.position).to eq 3
+ expect(list4.reload.position).to eq 4
+ expect(list5.reload.position).to eq 5
+ end
+
+ it 'keeps position of lists when new positon is equal to old position' 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)
+
+ service = described_class.new(project, { list_id: list2.id, position: 2 })
+
+ expect(service.execute).to eq false
+ expect(list1.reload.position).to eq 1
+ expect(list2.reload.position).to eq 2
+ expect(list3.reload.position).to eq 3
+ expect(list4.reload.position).to eq 4
+ expect(list5.reload.position).to eq 5
+ end
+
+ it 'decrements position of intermediate lists when new position is greater than old position' 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)
+
+ service = described_class.new(project, { list_id: list2.id, position: 5 })
+
+ expect(service.execute).to eq true
+ expect(list1.reload.position).to eq 1
+ expect(list2.reload.position).to eq 5
+ expect(list3.reload.position).to eq 2
+ expect(list4.reload.position).to eq 3
+ expect(list5.reload.position).to eq 4
+ end
+
+ it 'increments position of intermediate lists when when new position is lower than old position' 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)
+
+ service = described_class.new(project, { list_id: list5.id, position: 2 })
+
+ expect(service.execute).to eq true
+ expect(list1.reload.position).to eq 1
+ expect(list2.reload.position).to eq 3
+ expect(list3.reload.position).to eq 4
+ expect(list4.reload.position).to eq 5
+ expect(list5.reload.position).to eq 2
+ end
+ end
+end