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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-01 18:07:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-01 18:07:45 +0300
commit1219a9dce91f4edbc135dfc08299b4122b4825a8 (patch)
treee7d12a55d75a2d56e60d9527bef3724e3578866d /spec/lib/gitlab/background_migration
parent1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/background_migration')
-rw-r--r--spec/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/populate_user_highest_roles_table_spec.rb71
-rw-r--r--spec/lib/gitlab/background_migration/recalculate_project_authorizations_spec.rb4
4 files changed, 74 insertions, 5 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config_spec.rb b/spec/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config_spec.rb
index 91ede05f395..44f5c3380a1 100644
--- a/spec/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_project_fullpath_in_repo_config_spec.rb
@@ -39,7 +39,7 @@ describe Gitlab::BackgroundMigration::BackfillProjectFullpathInRepoConfig, schem
end
it 'raises OrphanedNamespaceError when any parent namespace does not exist' do
- subgroup.update_attribute(:parent_id, namespaces.maximum(:id).succ)
+ subgroup.update_attribute(:parent_id, non_existing_record_id)
expect { project.full_path }.to raise_error(Gitlab::BackgroundMigration::BackfillProjectFullpathInRepoConfig::OrphanedNamespaceError)
end
diff --git a/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb b/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb
index 510a0074554..cfaef1578a9 100644
--- a/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb
@@ -90,7 +90,7 @@ describe Gitlab::BackgroundMigration::BackfillProjectRepositories do
it 'raises OrphanedNamespaceError when any parent namespace does not exist' do
subgroup = create(:group, parent: group)
project_orphaned_namespace = create(:project, name: 'baz', path: 'baz', namespace: subgroup, storage_version: nil)
- subgroup.update_column(:parent_id, Namespace.maximum(:id).succ)
+ subgroup.update_column(:parent_id, non_existing_record_id)
project = described_class.find(project_orphaned_namespace.id)
project.route.destroy
diff --git a/spec/lib/gitlab/background_migration/populate_user_highest_roles_table_spec.rb b/spec/lib/gitlab/background_migration/populate_user_highest_roles_table_spec.rb
new file mode 100644
index 00000000000..be661d5b83e
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/populate_user_highest_roles_table_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::BackgroundMigration::PopulateUserHighestRolesTable, schema: 20200311130802 do
+ let(:members) { table(:members) }
+ let(:users) { table(:users) }
+ let(:user_highest_roles) { table(:user_highest_roles) }
+
+ def create_user(id, params = {})
+ user_params = {
+ id: id,
+ state: 'active',
+ user_type: nil,
+ bot_type: nil,
+ ghost: nil,
+ email: "user#{id}@example.com",
+ projects_limit: 0
+ }.merge(params)
+
+ users.create(user_params)
+ end
+
+ def create_member(id, access_level, params = {})
+ params = {
+ user_id: id,
+ access_level: access_level,
+ source_id: 1,
+ source_type: 'Group',
+ notification_level: 0
+ }.merge(params)
+
+ members.create(params)
+ end
+
+ before do
+ create_user(1)
+ create_user(2, state: 'blocked')
+ create_user(3, user_type: 2)
+ create_user(4)
+ create_user(5, bot_type: 1)
+ create_user(6, ghost: true)
+ create_user(7, ghost: false)
+ create_user(8)
+
+ create_member(1, 40)
+ create_member(7, 30)
+ create_member(8, 20, requested_at: Time.current)
+
+ user_highest_roles.create(user_id: 1, highest_access_level: 50)
+ end
+
+ describe '#perform' do
+ it 'creates user_highest_roles rows according to users', :aggregate_failures do
+ expect { subject.perform(1, 8) }.to change(UserHighestRole, :count).from(1).to(4)
+
+ created_or_updated_rows = [
+ { 'user_id' => 1, 'highest_access_level' => 40 },
+ { 'user_id' => 4, 'highest_access_level' => nil },
+ { 'user_id' => 7, 'highest_access_level' => 30 },
+ { 'user_id' => 8, 'highest_access_level' => nil }
+ ]
+
+ rows = user_highest_roles.order(:user_id).map do |row|
+ row.attributes.slice('user_id', 'highest_access_level')
+ end
+
+ expect(rows).to match_array(created_or_updated_rows)
+ end
+ end
+end
diff --git a/spec/lib/gitlab/background_migration/recalculate_project_authorizations_spec.rb b/spec/lib/gitlab/background_migration/recalculate_project_authorizations_spec.rb
index 4699cc42b38..ba87312e2bf 100644
--- a/spec/lib/gitlab/background_migration/recalculate_project_authorizations_spec.rb
+++ b/spec/lib/gitlab/background_migration/recalculate_project_authorizations_spec.rb
@@ -234,10 +234,8 @@ describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, schema:
end
context 'deleted user' do
- let(:nonexistent_user_id) { User.maximum(:id).to_i + 999 }
-
it 'does not fail' do
- expect { described_class.new.perform([nonexistent_user_id]) }.not_to raise_error
+ expect { described_class.new.perform([non_existing_record_id]) }.not_to raise_error
end
end
end