diff options
author | Valery Sizov <valery@gitlab.com> | 2017-03-10 19:04:37 +0200 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2017-03-14 14:11:59 +0200 |
commit | e752d6d157321f9f10d70cdef1ce1992e263634f (patch) | |
tree | 8e3ba97429243e13b322d81bb60b5b4f3e4b7d9f /spec | |
parent | b84723ac8bf8572c3d261980ab053dda52bc78dd (diff) | |
download | gitlab-ce-e752d6d157321f9f10d70cdef1ce1992e263634f.tar.gz |
[Issue sorting]Addressed review commentsfix_relative_position_calculation
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/concerns/relative_positioning_spec.rb | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/spec/models/concerns/relative_positioning_spec.rb b/spec/models/concerns/relative_positioning_spec.rb index ebbf14fb5ba..255b584a85e 100644 --- a/spec/models/concerns/relative_positioning_spec.rb +++ b/spec/models/concerns/relative_positioning_spec.rb @@ -66,6 +66,34 @@ describe Issue, 'RelativePositioning' do end end + describe '#shift_after?' do + it 'returns true' do + issue.update(relative_position: issue1.relative_position - 1) + + expect(issue.shift_after?).to be_truthy + end + + it 'returns false' do + issue.update(relative_position: issue1.relative_position - 2) + + expect(issue.shift_after?).to be_falsey + end + end + + describe '#shift_before?' do + it 'returns true' do + issue.update(relative_position: issue1.relative_position + 1) + + expect(issue.shift_before?).to be_truthy + end + + it 'returns false' do + issue.update(relative_position: issue1.relative_position + 2) + + expect(issue.shift_before?).to be_falsey + end + end + describe '#move_between' do it 'positions issue between two other' do new_issue.move_between(issue, issue1) @@ -118,7 +146,7 @@ describe Issue, 'RelativePositioning' do new_issue.move_between(nil, issue1) - expect(new_issue.relative_position).to eq(6000 - RelativePositioning::DISTANCE) + expect(new_issue.relative_position).to eq(6000 - RelativePositioning::IDEAL_DISTANCE) end it 'positions issue closer to the middle if we are at the very bottom' do @@ -127,7 +155,7 @@ describe Issue, 'RelativePositioning' do new_issue.move_between(issue, nil) - expect(new_issue.relative_position).to eq(6000 + RelativePositioning::DISTANCE) + expect(new_issue.relative_position).to eq(6000 + RelativePositioning::IDEAL_DISTANCE) end it 'positions issue in the middle of other two if distance is not big enough' do @@ -138,5 +166,39 @@ describe Issue, 'RelativePositioning' do expect(new_issue.relative_position).to eq(250) end + + it 'positions issue in the middle of other two is there is no place' do + issue.update relative_position: 100 + issue1.update relative_position: 101 + + new_issue.move_between(issue, issue1) + + expect(new_issue.relative_position).to be_between(issue.relative_position, issue1.relative_position) + end + + it 'uses rebalancing if there is no place' do + issue.update relative_position: 100 + issue1.update relative_position: 101 + issue2 = create(:issue, relative_position: 102, project: project) + new_issue.update relative_position: 103 + + new_issue.move_between(issue1, issue2) + new_issue.save! + + expect(new_issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position) + expect(issue.reload.relative_position).not_to eq(100) + end + + it 'positions issue right if we pass none-sequential parameters' do + issue.update relative_position: 99 + issue1.update relative_position: 101 + issue2 = create(:issue, relative_position: 102, project: project) + new_issue.update relative_position: 103 + + new_issue.move_between(issue, issue2) + new_issue.save! + + expect(new_issue.relative_position).to be(100) + end end end |