summaryrefslogtreecommitdiff
path: root/spec/migrations
diff options
context:
space:
mode:
authorToon Claes <toon@iotcl.com>2017-08-16 14:46:26 +0200
committerToon Claes <toon@iotcl.com>2017-08-22 14:29:54 +0200
commit2074f39a47645b5ea453adfba84247f2fcc4f3c7 (patch)
tree3f2aab56177cf0704faa8d739ce61acc7055a99e /spec/migrations
parentce89c425fe51d2317322350bbd8a364c08d97d21 (diff)
downloadgitlab-ce-2074f39a47645b5ea453adfba84247f2fcc4f3c7.tar.gz
Migration to remove pending delete projects with non-existing namespace
There might be some projects where the namespace was removed, but the project wasn't. For these the projects still have a `namespace_id` set. So this adds a post-deploy migration remove all projects that are pending delete, and have a `namespace_id` that is non-existing.
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb b/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb
new file mode 100644
index 00000000000..7879105a334
--- /dev/null
+++ b/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb')
+
+describe CleanupNonexistingNamespacePendingDeleteProjects do
+ before do
+ # Stub after_save callbacks that will fail when Project has invalid namespace
+ allow_any_instance_of(Project).to receive(:ensure_storage_path_exist).and_return(nil)
+ allow_any_instance_of(Project).to receive(:update_project_statistics).and_return(nil)
+ end
+
+ describe '#up' do
+ set(:some_project) { create(:project) }
+
+ it 'only cleans up when namespace does not exist' do
+ create(:project, pending_delete: true)
+ project = build(:project, pending_delete: true, namespace: nil, namespace_id: Namespace.maximum(:id).to_i.succ)
+ project.save(validate: false)
+
+ expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id]])
+
+ described_class.new.up
+ end
+
+ it 'does nothing when no pending delete projects without namespace found' do
+ create(:project, pending_delete: true, namespace: create(:namespace))
+
+ expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async)
+
+ described_class.new.up
+ end
+ end
+end