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

backfill_vs_code_settings_uuid_spec.rb « background_migration « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bf1fce4094ea053cb4e6ed33390c556c659cd782 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BackgroundMigration::BackfillVsCodeSettingsUuid, schema: 20231130140901, feature_category: :web_ide do
  let!(:vs_code_settings) { table(:vs_code_settings) }
  let!(:users) { table(:users) }

  let!(:user) do
    users.create!(
      email: "test1@example.com",
      username: "test1",
      notification_email: "test@example.com",
      name: "test",
      state: "active",
      projects_limit: 10)
  end

  subject(:migration) do
    described_class.new(
      start_id: vs_code_setting_one.id,
      end_id: vs_code_setting_two.id,
      batch_table: :vs_code_settings,
      batch_column: :id,
      sub_batch_size: 100,
      pause_ms: 0,
      connection: ActiveRecord::Base.connection
    )
  end

  describe "#perform" do
    context 'when it finds vs_code_setting rows with empty uuid' do
      let(:vs_code_setting_one) do
        vs_code_settings.create!(user_id: user.id, setting_type: 'profiles', content: '{}')
      end

      let(:vs_code_setting_two) do
        vs_code_settings.create!(user_id: user.id, setting_type: 'tasks', content: '{}')
      end

      it 'populates uuid column with a generated uuid' do
        expect(vs_code_setting_one.uuid).to be_nil
        expect(vs_code_setting_two.uuid).to be_nil

        migration.perform

        expect(vs_code_setting_one.reload.uuid).not_to be_nil
        expect(vs_code_setting_two.reload.uuid).not_to be_nil
      end
    end

    context 'when it finds vs_code_setting rows with non-empty uuid' do
      let(:vs_code_setting_one) do
        vs_code_settings.create!(user_id: user.id, setting_type: 'profiles', content: '{}', uuid: SecureRandom.uuid)
      end

      let(:vs_code_setting_two) do
        vs_code_settings.create!(user_id: user.id, setting_type: 'tasks', content: '{}')
      end

      it 'populates uuid column with a generated uuid' do
        expect(vs_code_setting_one.uuid).not_to be_nil
        expect(vs_code_setting_two.uuid).to be_nil

        previous_uuid = vs_code_setting_one.uuid

        migration.perform

        expect(vs_code_setting_one.reload.uuid).to eq(previous_uuid)
        expect(vs_code_setting_two.reload.uuid).not_to be_nil
      end
    end
  end
end