Commit 84fd43cf authored by Alex Kalderimis's avatar Alex Kalderimis

Allow create_space methods to be called without args

parent 08314ee8
...@@ -171,12 +171,12 @@ module RelativePositioning ...@@ -171,12 +171,12 @@ module RelativePositioning
object.reset object.reset
end end
def create_space_left(gap: nil) def create_space_left
move_sequence_before(false, next_gap: gap) find_next_gap_before.tap { |gap| move_sequence_before(false, next_gap: gap) }
end end
def create_space_right(gap: nil) def create_space_right
move_sequence_after(false, next_gap: gap) find_next_gap_after.tap { |gap| move_sequence_after(false, next_gap: gap) }
end end
# Moves the sequence before the current item to the middle of the next gap # Moves the sequence before the current item to the middle of the next gap
...@@ -386,16 +386,11 @@ module RelativePositioning ...@@ -386,16 +386,11 @@ module RelativePositioning
return [pos_left, pos_right] unless gap_too_small?(pos_left, pos_right) return [pos_left, pos_right] unless gap_too_small?(pos_left, pos_right)
gap = rhs.find_next_gap_before gap = rhs.create_space_left
[pos_left - gap.delta, pos_right]
if gap.present? rescue NoSpaceLeft
rhs.create_space_left(gap: gap) gap = lhs.create_space_right
[pos_left - gap.delta, pos_right] [pos_left, pos_right + gap.delta]
else
gap = lhs.find_next_gap_after
lhs.create_space_right(gap: gap)
[pos_left, pos_right + gap.delta]
end
end end
# This method takes two integer values (positions) and # This method takes two integer values (positions) and
......
...@@ -39,8 +39,8 @@ RSpec.describe EpicIssue do ...@@ -39,8 +39,8 @@ RSpec.describe EpicIssue do
let_it_be_with_reload(:middle) { create(:epic, group: epic.group, parent: epic, relative_position: 101) } let_it_be_with_reload(:middle) { create(:epic, group: epic.group, parent: epic, relative_position: 101) }
let_it_be_with_reload(:right) { create(:epic_issue, epic: epic, relative_position: 102) } let_it_be_with_reload(:right) { create(:epic_issue, epic: epic, relative_position: 102) }
it 'can create space by using move_sequence_after' do it 'can create space to the right' do
left.move_sequence_after RelativePositioning.mover.context(left).create_space_right
[left, middle, right].each(&:reset) [left, middle, right].each(&:reset)
expect(middle.relative_position - left.relative_position).to be > 1 expect(middle.relative_position - left.relative_position).to be > 1
...@@ -48,8 +48,8 @@ RSpec.describe EpicIssue do ...@@ -48,8 +48,8 @@ RSpec.describe EpicIssue do
expect(middle.relative_position).to be < right.relative_position expect(middle.relative_position).to be < right.relative_position
end end
it 'can create space by using move_sequence_before' do it 'can create space to the left' do
right.move_sequence_before RelativePositioning.mover.context(right).create_space_left
[left, middle, right].each(&:reset) [left, middle, right].each(&:reset)
expect(right.relative_position - middle.relative_position).to be > 1 expect(right.relative_position - middle.relative_position).to be > 1
......
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