Welcome to mirror list, hosted at ThFree Co, Russian Federation.

add_epics_relative_position_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bdfaacc2bf81a67ecd4d2bace00fc3bae6231c34 (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, feature_category: :portfolio_management 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