gitlab-org--gitlab-foss/spec/models/concerns/relative_positioning_spec.rb

105 lines
2.9 KiB
Ruby
Raw Normal View History

2017-02-27 10:45:55 -05:00
require 'spec_helper'
describe Issue, 'RelativePositioning' do
let(:project) { create(:empty_project) }
let(:issue) { create(:issue, project: project) }
let(:issue1) { create(:issue, project: project) }
2017-03-07 06:42:17 -05:00
let(:new_issue) { create(:issue, project: project) }
2017-02-27 10:45:55 -05:00
before do
[issue, issue1].each do |issue|
issue.move_to_end && issue.save
end
end
describe '#min_relative_position' do
2017-03-06 11:08:18 -05:00
it 'returns maximum position' do
expect(issue.min_relative_position).to eq issue.relative_position
2017-02-27 10:45:55 -05:00
end
end
2017-03-06 11:08:18 -05:00
describe '#max_relative_position' do
2017-02-27 10:45:55 -05:00
it 'returns maximum position' do
expect(issue.max_relative_position).to eq issue1.relative_position
end
end
describe '#prev_relative_position' do
it 'returns previous position if there is an issue above' do
expect(issue1.prev_relative_position).to eq issue.relative_position
end
it 'returns minimum position if there is no issue above' do
expect(issue.prev_relative_position).to eq RelativePositioning::MIN_POSITION
end
end
describe '#next_relative_position' do
it 'returns next position if there is an issue below' do
expect(issue.next_relative_position).to eq issue1.relative_position
end
it 'returns next position if there is no issue below' do
expect(issue1.next_relative_position).to eq RelativePositioning::MAX_POSITION
end
end
describe '#move_before' do
it 'moves issue before' do
[issue1, issue].each(&:move_to_end)
issue.move_before(issue1)
expect(issue.relative_position).to be < issue1.relative_position
end
end
describe '#move_after' do
it 'moves issue after' do
[issue, issue1].each(&:move_to_end)
2017-02-27 10:45:55 -05:00
issue.move_after(issue1)
2017-02-27 10:45:55 -05:00
expect(issue.relative_position).to be > issue1.relative_position
2017-02-27 10:45:55 -05:00
end
end
describe '#move_to_end' do
it 'moves issue to the end' do
new_issue.move_to_end
expect(new_issue.relative_position).to be > issue1.relative_position
end
end
describe '#move_between' do
it 'positions issue between two other' do
new_issue.move_between(issue, issue1)
expect(new_issue.relative_position).to be > issue.relative_position
expect(new_issue.relative_position).to be < issue1.relative_position
end
2017-03-06 11:08:18 -05:00
it 'positions issue between on top' do
new_issue.move_between(nil, issue)
2017-02-27 10:45:55 -05:00
2017-03-06 11:08:18 -05:00
expect(new_issue.relative_position).to be < issue.relative_position
2017-02-27 10:45:55 -05:00
end
2017-03-06 11:08:18 -05:00
it 'positions issue between to end' do
new_issue.move_between(issue1, nil)
2017-02-27 10:45:55 -05:00
2017-03-06 11:08:18 -05:00
expect(new_issue.relative_position).to be > issue1.relative_position
2017-02-27 10:45:55 -05:00
end
2017-03-06 11:08:18 -05:00
it 'positions issues even when after and before positions are the same' do
issue1.update relative_position: issue.relative_position
2017-02-27 10:45:55 -05:00
2017-03-06 11:08:18 -05:00
new_issue.move_between(issue, issue1)
2017-02-27 10:45:55 -05:00
2017-03-06 11:08:18 -05:00
expect(new_issue.relative_position).to be > issue.relative_position
expect(issue.relative_position).to be < issue1.relative_position
2017-02-27 10:45:55 -05:00
end
end
end