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-06-08 18:08:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-08 18:08:20 +0300
commit5693fb6ba7d21ba7b79775543a3f195eb989664b (patch)
treea9038b20872f0f3bd35de034bfb40e533435bfa5 /spec/migrations
parentf149549c3432ffb179f6904e4ba0ea64027202d0 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/cleanup_projects_with_missing_namespace_spec.rb32
-rw-r--r--spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb96
2 files changed, 116 insertions, 12 deletions
diff --git a/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb b/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb
index 06b6d5e3b46..27c954d2984 100644
--- a/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb
+++ b/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb
@@ -5,10 +5,6 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200511080113_add_projects_foreign_key_to_namespaces.rb')
require Rails.root.join('db', 'post_migrate', '20200511083541_cleanup_projects_with_missing_namespace.rb')
-LOST_AND_FOUND_GROUP = 'lost-and-found'
-USER_TYPE_GHOST = 5
-ACCESS_LEVEL_OWNER = 50
-
# In order to test the CleanupProjectsWithMissingNamespace migration, we need
# to first create an orphaned project (one with an invalid namespace_id)
# and then run the migration to check that the project was properly cleaned up
@@ -77,31 +73,39 @@ describe CleanupProjectsWithMissingNamespace, :migration, schema: SchemaVersionF
end
it 'creates the ghost user' do
- expect(users.where(user_type: USER_TYPE_GHOST).count).to eq(0)
+ expect(users.where(user_type: described_class::User::USER_TYPE_GHOST).count).to eq(0)
disable_migrations_output { migrate! }
- expect(users.where(user_type: USER_TYPE_GHOST).count).to eq(1)
+ expect(users.where(user_type: described_class::User::USER_TYPE_GHOST).count).to eq(1)
end
it 'creates the lost-and-found group, owned by the ghost user' do
expect(
- Group.where(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%")).count
+ described_class::Group.where(
+ described_class::Group
+ .arel_table[:name]
+ .matches("#{described_class::User::LOST_AND_FOUND_GROUP}%")
+ ).count
).to eq(0)
disable_migrations_output { migrate! }
- ghost_user = users.find_by(user_type: USER_TYPE_GHOST)
+ ghost_user = users.find_by(user_type: described_class::User::USER_TYPE_GHOST)
expect(
- Group
+ described_class::Group
.joins('INNER JOIN members ON namespaces.id = members.source_id')
.where('namespaces.type = ?', 'Group')
.where('members.type = ?', 'GroupMember')
.where('members.source_type = ?', 'Namespace')
.where('members.user_id = ?', ghost_user.id)
.where('members.requested_at IS NULL')
- .where('members.access_level = ?', ACCESS_LEVEL_OWNER)
- .where(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%"))
+ .where('members.access_level = ?', described_class::ACCESS_LEVEL_OWNER)
+ .where(
+ described_class::Group
+ .arel_table[:name]
+ .matches("#{described_class::User::LOST_AND_FOUND_GROUP}%")
+ )
.count
).to eq(1)
end
@@ -114,7 +118,11 @@ describe CleanupProjectsWithMissingNamespace, :migration, schema: SchemaVersionF
disable_migrations_output { migrate! }
- lost_and_found_group = Group.find_by(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%"))
+ lost_and_found_group = described_class::Group.find_by(
+ described_class::Group
+ .arel_table[:name]
+ .matches("#{described_class::User::LOST_AND_FOUND_GROUP}%")
+ )
orphaned_project = projects.find_by(id: orphaned_project.id)
expect(orphaned_project.visibility_level).to eq(0)
diff --git a/spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb b/spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb
new file mode 100644
index 00000000000..a7e03a7fb75
--- /dev/null
+++ b/spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb
@@ -0,0 +1,96 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require Rails.root.join('db', 'post_migrate', '20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb')
+
+describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration do
+ let(:users) { table(:users) }
+ let(:namespaces) { table(:namespaces) }
+ let(:members) { table(:members) }
+ let(:projects) { table(:projects) }
+ let(:routes) { table(:routes) }
+
+ before do
+ # Create a Ghost User and its namnespace, but skip the route
+ ghost_user = users.create!(
+ name: 'Ghost User',
+ username: 'ghost',
+ email: 'ghost@example.com',
+ user_type: described_class::User::USER_TYPE_GHOST,
+ projects_limit: 100,
+ state: :active,
+ bio: 'This is a "Ghost User"'
+ )
+
+ namespaces.create!(
+ name: 'Ghost User',
+ path: 'ghost',
+ owner_id: ghost_user.id,
+ visibility_level: 20
+ )
+
+ # Create the 'lost-and-found', owned by the Ghost user, but with no route
+ lost_and_found_group = namespaces.create!(
+ name: described_class::User::LOST_AND_FOUND_GROUP,
+ path: described_class::User::LOST_AND_FOUND_GROUP,
+ type: 'Group',
+ description: 'Group to store orphaned projects',
+ visibility_level: 0
+ )
+
+ members.create!(
+ type: 'GroupMember',
+ source_id: lost_and_found_group.id,
+ user_id: ghost_user.id,
+ source_type: 'Namespace',
+ access_level: described_class::User::ACCESS_LEVEL_OWNER,
+ notification_level: 3
+ )
+
+ # Add an orphaned project under 'lost-and-found' but with the wrong path in its route
+ orphaned_project = projects.create!(
+ name: 'orphaned_project',
+ path: 'orphaned_project',
+ visibility_level: 20,
+ archived: false,
+ namespace_id: lost_and_found_group.id
+ )
+
+ routes.create!(
+ source_id: orphaned_project.id,
+ source_type: 'Project',
+ path: 'orphaned_project',
+ name: 'orphaned_project',
+ created_at: Time.zone.now,
+ updated_at: Time.zone.now
+ )
+ end
+
+ it 'creates the route for the ghost user namespace' do
+ expect(routes.where(path: 'ghost').count).to eq(0)
+
+ disable_migrations_output { migrate! }
+
+ expect(routes.where(path: 'ghost').count).to eq(1)
+ end
+
+ it 'creates the route for the lost-and-found group' do
+ expect(routes.where(path: described_class::User::LOST_AND_FOUND_GROUP).count).to eq(0)
+
+ disable_migrations_output { migrate! }
+
+ expect(routes.where(path: described_class::User::LOST_AND_FOUND_GROUP).count).to eq(1)
+ end
+
+ it 'updates the route for the orphaned project' do
+ orphaned_project_route = routes.find_by(path: 'orphaned_project')
+ expect(orphaned_project_route.name).to eq('orphaned_project')
+
+ disable_migrations_output { migrate! }
+
+ updated_route = routes.find_by(id: orphaned_project_route.id)
+ expect(updated_route.path).to eq("#{described_class::User::LOST_AND_FOUND_GROUP}/orphaned_project")
+ expect(updated_route.name).to eq("#{described_class::User::LOST_AND_FOUND_GROUP} / orphaned_project")
+ end
+end