diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 03:08:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-14 03:08:10 +0300 |
commit | c77ea1f6860ba657eefd5a06e46db8d212b21f08 (patch) | |
tree | 9330894c4c318e04a71f38ce85c82d3a23192fcb /spec/migrations/20230605095810_ensure_default_organization_spec.rb | |
parent | 04cc87ee46c1c0b6b4eb7df964b3115dd2578877 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations/20230605095810_ensure_default_organization_spec.rb')
-rw-r--r-- | spec/migrations/20230605095810_ensure_default_organization_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/migrations/20230605095810_ensure_default_organization_spec.rb b/spec/migrations/20230605095810_ensure_default_organization_spec.rb new file mode 100644 index 00000000000..97e9a4c54e7 --- /dev/null +++ b/spec/migrations/20230605095810_ensure_default_organization_spec.rb @@ -0,0 +1,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 |