2018-01-10 09:48:53 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20171207150343_remove_soft_removed_objects.rb')
|
|
|
|
|
|
|
|
describe RemoveSoftRemovedObjects, :migration do
|
|
|
|
describe '#up' do
|
2018-06-18 13:15:58 -04:00
|
|
|
let!(:groups) do
|
|
|
|
table(:namespaces).tap do |t|
|
|
|
|
t.inheritance_column = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:routes) do
|
|
|
|
table(:routes).tap do |t|
|
|
|
|
t.inheritance_column = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-10 09:48:53 -05:00
|
|
|
it 'removes various soft removed objects' do
|
|
|
|
5.times do
|
|
|
|
create_with_deleted_at(:issue)
|
|
|
|
end
|
|
|
|
|
2018-03-30 11:18:44 -04:00
|
|
|
regular_issue = create(:issue) # rubocop:disable RSpec/FactoriesInMigrationSpecs
|
2018-01-10 09:48:53 -05:00
|
|
|
|
|
|
|
run_migration
|
|
|
|
|
|
|
|
expect(Issue.count).to eq(1)
|
|
|
|
expect(Issue.first).to eq(regular_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the temporary indexes once soft removed data has been removed' do
|
|
|
|
migration = described_class.new
|
|
|
|
|
|
|
|
run_migration
|
|
|
|
|
|
|
|
disable_migrations_output do
|
|
|
|
expect(migration.temporary_index_exists?(Issue)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes routes of soft removed personal namespaces' do
|
|
|
|
namespace = create_with_deleted_at(:namespace)
|
2018-06-18 13:15:58 -04:00
|
|
|
group = groups.create!(name: 'group', path: 'group_path', type: 'Group')
|
|
|
|
routes.create!(source_id: group.id, source_type: 'Group', name: 'group', path: 'group_path')
|
2018-01-10 09:48:53 -05:00
|
|
|
|
2018-06-18 13:15:58 -04:00
|
|
|
expect(routes.where(source_id: namespace.id).exists?).to eq(true)
|
|
|
|
expect(routes.where(source_id: group.id).exists?).to eq(true)
|
2018-01-10 09:48:53 -05:00
|
|
|
|
|
|
|
run_migration
|
|
|
|
|
2018-06-18 13:15:58 -04:00
|
|
|
expect(routes.where(source_id: namespace.id).exists?).to eq(false)
|
|
|
|
expect(routes.where(source_id: group.id).exists?).to eq(true)
|
2018-01-10 09:48:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules the removal of soft removed groups' do
|
2018-06-18 13:15:58 -04:00
|
|
|
group = create_deleted_group
|
2018-03-30 11:18:44 -04:00
|
|
|
admin = create(:user, admin: true) # rubocop:disable RSpec/FactoriesInMigrationSpecs
|
2018-01-10 09:48:53 -05:00
|
|
|
|
|
|
|
expect_any_instance_of(GroupDestroyWorker)
|
|
|
|
.to receive(:perform)
|
|
|
|
.with(group.id, admin.id)
|
|
|
|
|
|
|
|
run_migration
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not remove soft removed groups when no admin user could be found' do
|
2018-06-18 13:15:58 -04:00
|
|
|
create_deleted_group
|
2018-01-10 09:48:53 -05:00
|
|
|
|
|
|
|
expect_any_instance_of(GroupDestroyWorker)
|
|
|
|
.not_to receive(:perform)
|
|
|
|
|
|
|
|
run_migration
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_migration
|
|
|
|
disable_migrations_output do
|
|
|
|
migrate!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_with_deleted_at(*args)
|
2018-03-30 11:18:44 -04:00
|
|
|
row = create(*args) # rubocop:disable RSpec/FactoriesInMigrationSpecs
|
2018-01-10 09:48:53 -05:00
|
|
|
|
|
|
|
# We set "deleted_at" this way so we don't run into any column cache issues.
|
|
|
|
row.class.where(id: row.id).update_all(deleted_at: 1.year.ago)
|
|
|
|
|
|
|
|
row
|
|
|
|
end
|
2018-06-18 13:15:58 -04:00
|
|
|
|
|
|
|
def create_deleted_group
|
|
|
|
group = groups.create!(name: 'group', path: 'group_path', type: 'Group')
|
|
|
|
routes.create!(source_id: group.id, source_type: 'Group', name: 'group', path: 'group_path')
|
|
|
|
|
|
|
|
groups.where(id: group.id).update_all(deleted_at: 1.year.ago)
|
|
|
|
|
|
|
|
group
|
|
|
|
end
|
2018-01-10 09:48:53 -05:00
|
|
|
end
|