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-02-14 00:08:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-14 00:08:59 +0300
commitd466ee5042520ad078fe050cb078d81dc2ebe196 (patch)
tree5648eb1aee8aeff5b5c5ff4669a184fd7676f778 /spec/migrations
parent6a9d7c009e4e5975a89bcc3e458da4b3ec484bd1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/schedule_recalculate_project_authorizations_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/migrations/schedule_recalculate_project_authorizations_spec.rb b/spec/migrations/schedule_recalculate_project_authorizations_spec.rb
new file mode 100644
index 00000000000..77ad2b2dc8e
--- /dev/null
+++ b/spec/migrations/schedule_recalculate_project_authorizations_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20200204113223_schedule_recalculate_project_authorizations.rb')
+
+describe ScheduleRecalculateProjectAuthorizations, :migration do
+ let(:users_table) { table(:users) }
+ let(:namespaces_table) { table(:namespaces) }
+ let(:projects_table) { table(:projects) }
+ let(:project_authorizations_table) { table(:project_authorizations) }
+
+ let(:user1) { users_table.create!(name: 'user1', email: 'user1@example.com', projects_limit: 1) }
+ let(:user2) { users_table.create!(name: 'user2', email: 'user2@example.com', projects_limit: 1) }
+ let(:group) { namespaces_table.create!(id: 1, type: 'Group', name: 'group', path: 'group') }
+ let(:project) do
+ projects_table.create!(id: 1, name: 'project', path: 'project',
+ visibility_level: 0, namespace_id: group.id)
+ end
+
+ before do
+ stub_const("#{described_class}::BATCH_SIZE", 1)
+
+ project_authorizations_table.create!(user_id: user1.id, project_id: project.id, access_level: 30)
+ project_authorizations_table.create!(user_id: user2.id, project_id: project.id, access_level: 30)
+ end
+
+ it 'schedules background migration' do
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migrate!
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq(2)
+ expect(described_class::MIGRATION).to be_scheduled_migration([user1.id])
+ expect(described_class::MIGRATION).to be_scheduled_migration([user2.id])
+ end
+ end
+ end
+
+ it 'ignores projects with higher id than maximum group id' do
+ another_user = users_table.create!(name: 'another user', email: 'another-user@example.com',
+ projects_limit: 1)
+ ignored_project = projects_table.create!(id: 2, name: 'ignored-project', path: 'ignored-project',
+ visibility_level: 0, namespace_id: group.id)
+ project_authorizations_table.create!(user_id: another_user.id, project_id: ignored_project.id,
+ access_level: 30)
+
+ Sidekiq::Testing.fake! do
+ Timecop.freeze do
+ migrate!
+
+ expect(BackgroundMigrationWorker.jobs.size).to eq(2)
+ expect(described_class::MIGRATION).to be_scheduled_migration([user1.id])
+ expect(described_class::MIGRATION).to be_scheduled_migration([user2.id])
+ end
+ end
+ end
+end