Commit 63687c9e authored by Adam Hegyi's avatar Adam Hegyi

Ensure VSM stage has relative position

Ensure that all VSM stage has relative position before moving a stage.
This fixes a problem where moving a stage after another stage (where the
relative position was null) sets the position incorrectly.
parent 5984046c
......@@ -56,6 +56,9 @@ module Analytics
# rubocop: enable CodeReuse/ActiveRecord
def handle_position_change
# make sure that unpositioned items have relative_position
@stage.class.move_nulls_to_end(parent.cycle_analytics_stages.ordered)
move_before_id = params.delete(:move_before_id)
move_after_id = params.delete(:move_after_id)
......
......@@ -119,6 +119,22 @@ describe Analytics::CycleAnalytics::Stages::UpdateService do
let!(:middle_stage) { create(:cycle_analytics_group_stage, group: group, relative_position: 11) }
let!(:last_stage) { create(:cycle_analytics_group_stage, group: group, relative_position: 12) }
context 'when there are stages without position' do
let!(:unpositioned_stage1) { create(:cycle_analytics_group_stage, group: group) }
let!(:unpositioned_stage2) { create(:cycle_analytics_group_stage, group: group) }
before do
params[:id] = first_stage.id
params[:move_after_id] = unpositioned_stage2.id
end
it 'when moving the stage down' do
subject
expect(persisted_stages.last(3)).to eq([unpositioned_stage1, unpositioned_stage2, first_stage])
end
end
context 'when moving the stage down' do
before do
params[:id] = first_stage.id
......
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