2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe ProjectDestroyWorker, feature_category: :source_code_management do
|
|
|
|
let_it_be(:project) { create(:project, :repository, pending_delete: true) }
|
|
|
|
let_it_be(:repository) { project.repository.raw }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
let(:user) { project.first_owner }
|
|
|
|
|
|
|
|
subject(:worker) { described_class.new }
|
|
|
|
|
|
|
|
include_examples 'an idempotent worker' do
|
|
|
|
let(:job_args) { [project.id, user.id, {}] }
|
|
|
|
|
|
|
|
it 'does not change projects when run twice' do
|
|
|
|
expect { worker.perform(project.id, user.id, {}) }.to change { Project.count }.by(-1)
|
|
|
|
expect { worker.perform(project.id, user.id, {}) }.not_to change { Project.count }
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe '#perform' do
|
|
|
|
it 'deletes the project' do
|
2023-05-27 22:25:52 +05:30
|
|
|
worker.perform(project.id, user.id, {})
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(Project.all).not_to include(project)
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(repository).not_to exist
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'does not raise error when project could not be found' do
|
|
|
|
expect do
|
2023-05-27 22:25:52 +05:30
|
|
|
worker.perform(-1, user.id, {})
|
2017-09-10 17:25:29 +05:30
|
|
|
end.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when user could not be found' do
|
|
|
|
expect do
|
2023-05-27 22:25:52 +05:30
|
|
|
worker.perform(project.id, -1, {})
|
2017-09-10 17:25:29 +05:30
|
|
|
end.not_to raise_error
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|