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

20230723203612_backfill_default_branch_protection_application_setting_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dcb65e22196f3a382822890799c9875da5b492d9 (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
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe BackfillDefaultBranchProtectionApplicationSetting, :migration, feature_category: :database do
  let(:application_settings_table) { table(:application_settings) }

  before do
    5.times do |branch_protection|
      application_settings_table.create!(default_branch_protection: branch_protection,
        default_branch_protection_defaults: {})
    end
  end

  it 'schedules a new batched migration' do
    reversible_migration do |migration|
      migration.before -> {
        5.times do |branch_protection|
          expect(migrated_attribute(branch_protection)).to eq({})
        end
      }

      migration.after -> {
        expect(migrated_attribute(0)).to eq({ "allow_force_push" => true,
                                              "allowed_to_merge" => [{ "access_level" => 30 }],
                                              "allowed_to_push" => [{ "access_level" => 30 }] })
        expect(migrated_attribute(1)).to eq({ "allow_force_push" => false,
                                              "allowed_to_merge" => [{ "access_level" => 30 }],
                                              "allowed_to_push" => [{ "access_level" => 30 }] })
        expect(migrated_attribute(2)).to eq({ "allow_force_push" => false,
                                              "allowed_to_merge" => [{ "access_level" => 40 }],
                                              "allowed_to_push" => [{ "access_level" => 40 }] })
        expect(migrated_attribute(3)).to eq({ "allow_force_push" => true,
                                              "allowed_to_merge" => [{ "access_level" => 30 }],
                                              "allowed_to_push" => [{ "access_level" => 40 }] })
        expect(migrated_attribute(4)).to eq({ "allow_force_push" => true,
                                              "allowed_to_merge" => [{ "access_level" => 30 }],
                                              "allowed_to_push" => [{ "access_level" => 40 }],
                                              "developer_can_initial_push" => true })
      }
    end
  end

  def migrated_attribute(branch_protection)
    application_settings_table
      .where(default_branch_protection: branch_protection)
      .last.default_branch_protection_defaults
  end
end