Skip to content

Commit

Permalink
Fix stack deletion take two
Browse files Browse the repository at this point in the history
  • Loading branch information
DazWorrall committed Nov 13, 2024
1 parent 6b417ca commit 81e4851
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/jobs/shipit/destroy_stack_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ def perform(stack)
commit_deployments_ids = Shipit::CommitDeployment.where(task_id: tasks_ids).pluck(:id)
Shipit::CommitDeploymentStatus.where(commit_deployment_id: commit_deployments_ids).in_batches(&:delete_all)
Shipit::CommitDeployment.where(id: commit_deployments_ids).in_batches(&:delete_all)
Shipit::Status.where(commit_id: commits_ids).in_batches(&:delete_all)
Shipit::Commit.where(id: commits_ids).in_batches(&:delete_all)

Shipit::Status.where(commit_id: commits_ids).find_in_batches do |batch|
Shipit::Status.where(id: batch.map(&:id)).delete_all
end

Shipit::Commit.where(id: commits_ids).find_in_batches do |batch|
Shipit::Commit.where(id: batch.map(&:id)).delete_all
end

Shipit::GithubHook.where(stack_id: stack.id).destroy_all
Shipit::Hook.where(stack_id: stack.id).in_batches(&:delete_all)
Shipit::MergeRequest.where(stack_id: stack.id).in_batches(&:delete_all)
Expand Down
9 changes: 9 additions & 0 deletions test/jobs/destroy_stack_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ class DestroyStackJobTest < ActiveSupport::TestCase
@job.perform(stack)
end
end

test "perform destroys the all Status of related commits" do
stack = shipit_stacks(:shipit)
Shipit.legacy_github_api.stubs(:remove_hook)

assert_changes -> { Status.count }, 'Statuses are not deleted' do
@job.perform(stack)
end
end
end
end

0 comments on commit 81e4851

Please sign in to comment.