Commit 48b2f366 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '32839-fix-relative-position-edge-case' into 'master'

Fix relative positioning when moving items down and there is no space

See merge request gitlab-org/gitlab!17781
parents 9abc9fe0 57c2400e
......@@ -127,6 +127,7 @@ module RelativePositioning
if pos_after && (pos_after - pos_before) < 2
before.move_sequence_after
pos_after = before.next_relative_position
end
self.relative_position = self.class.position_between(pos_before, pos_after)
......@@ -138,6 +139,7 @@ module RelativePositioning
if pos_before && (pos_after - pos_before) < 2
after.move_sequence_before
pos_before = after.prev_relative_position
end
self.relative_position = self.class.position_between(pos_before, pos_after)
......
---
title: Fix relative positioning when moving items down and there is no space
merge_request: 17781
author:
type: fixed
......@@ -84,6 +84,22 @@ RSpec.shared_examples 'a class that supports relative positioning' do
expect(item1.relative_position).to be < item2.relative_position
end
context 'when there is no space' do
let(:item3) { create(factory, default_params) }
before do
item1.update(relative_position: 1000)
item2.update(relative_position: 1001)
item3.update(relative_position: 1002)
end
it 'moves items correctly' do
item3.move_before(item2)
expect(item3.relative_position).to be_between(item1.reload.relative_position, item2.reload.relative_position).exclusive
end
end
end
describe '#move_after' do
......@@ -94,6 +110,22 @@ RSpec.shared_examples 'a class that supports relative positioning' do
expect(item1.relative_position).to be > item2.relative_position
end
context 'when there is no space' do
let(:item3) { create(factory, default_params) }
before do
item1.update(relative_position: 1000)
item2.update(relative_position: 1001)
item3.update(relative_position: 1002)
end
it 'moves items correctly' do
item1.move_after(item2)
expect(item1.relative_position).to be_between(item2.reload.relative_position, item3.reload.relative_position).exclusive
end
end
end
describe '#move_to_end' do
......@@ -196,7 +228,7 @@ RSpec.shared_examples 'a class that supports relative positioning' do
new_item.move_between(item1, item2)
expect(new_item.relative_position).to be_between(item1.relative_position, item2.relative_position)
expect(new_item.relative_position).to be_between(item1.relative_position, item2.relative_position).exclusive
end
it 'uses rebalancing if there is no place' do
......@@ -208,7 +240,7 @@ RSpec.shared_examples 'a class that supports relative positioning' do
new_item.move_between(item2, item3)
new_item.save!
expect(new_item.relative_position).to be_between(item2.relative_position, item3.relative_position)
expect(new_item.relative_position).to be_between(item2.relative_position, item3.relative_position).exclusive
expect(item1.reload.relative_position).not_to eq(100)
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