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

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

require 'spec_helper'

require_migration!

RSpec.describe EnsureDefaultOrganization, feature_category: :cell do
  let(:organization) { table(:organizations) }

  it "creates default organization if needed" do
    reversible_migration do |migration|
      migration.before -> {
        expect(organization.where(id: 1, name: 'Default', path: 'default')).to be_empty
      }
      migration.after -> {
        expect(organization.where(id: 1, name: 'Default', path: 'default')).not_to be_empty
      }
    end
  end

  context 'when default organization already exists' do
    it "does not creates default organization if needed" do
      reversible_migration do |migration|
        migration.before -> {
          organization.create!(id: 1, name: 'Default', path: 'default')

          expect(organization.where(id: 1, name: 'Default', path: 'default')).not_to be_empty
        }
        migration.after -> {
          expect(organization.where(id: 1, name: 'Default', path: 'default')).not_to be_empty
        }
      end
    end
  end

  context 'when the path is in use by another organization' do
    before do
      organization.create!(id: 1000, name: 'Default', path: 'default')
    end

    it "adds a random hash to the path" do
      reversible_migration do |migration|
        migration.after -> {
          default_organization = organization.where(id: 1)

          expect(default_organization.first.path).to match(/default-\w{6}/)
        }
      end
    end
  end
end