summaryrefslogtreecommitdiff
path: root/spec/migrations/add_epics_relative_position_spec.rb
blob: f3b7dd1727bc480068441c3f0e8ab89a5cfa7471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require 'spec_helper'

require_migration!

RSpec.describe AddEpicsRelativePosition, :migration do
  let(:groups) { table(:namespaces) }
  let(:epics) { table(:epics) }
  let(:users) { table(:users) }
  let(:user) { users.create!(name: 'user', email: 'email@example.org', projects_limit: 100) }
  let(:group) { groups.create!(name: 'gitlab', path: 'gitlab-org', type: 'Group') }

  let!(:epic1) { epics.create!(title: 'epic 1', title_html: 'epic 1', author_id: user.id, group_id: group.id, iid: 1) }
  let!(:epic2) { epics.create!(title: 'epic 2', title_html: 'epic 2', author_id: user.id, group_id: group.id, iid: 2) }
  let!(:epic3) { epics.create!(title: 'epic 3', title_html: 'epic 3', author_id: user.id, group_id: group.id, iid: 3) }

  it 'does nothing if epics table contains relative_position' do
    expect { migrate! }.not_to change { epics.pluck(:relative_position) }
  end

  it 'adds relative_position if missing and backfills it with ID value', :aggregate_failures do
    ActiveRecord::Base.connection.execute('ALTER TABLE epics DROP relative_position')

    migrate!

    expect(epics.pluck(:relative_position)).to match_array([epic1.id * 500, epic2.id * 500, epic3.id * 500])
  end
end