Skip to content

Commit

Permalink
Use destroy over delete for deleting unmapped routes (#4100)
Browse files Browse the repository at this point in the history
This triggers the deletion of associated resources, like
labels/annotations.

Otherwise this operation gives a FK error.
  • Loading branch information
Samze authored Nov 21, 2024
1 parent f3834d2 commit 53eb8d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/actions/space_delete_unmapped_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def delete(space)
space.routes_dataset.
exclude(guid: RouteMappingModel.select(:route_guid)).
exclude(id: RouteBinding.select(:route_id)).
delete
destroy
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/actions/space_delete_unmapped_routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ module VCAP::CloudController
expect { unbound_and_unmapped_route.refresh }.to raise_error Sequel::Error, 'Record not found'
end
end

context 'when the unmapped routes have labels and annotations' do
let!(:unmapped_route_1) { Route.make(domain: domain, space: space, host: 'unmapped1') }
let!(:label_1) { RouteLabelModel.make(key_name: 'k1', value: 'v1', resource_guid: unmapped_route_1.guid) }
let!(:annot_1) { RouteAnnotationModel.make(key_name: 'k1', value: 'v1', resource_guid: unmapped_route_1.guid) }

it 'deletes the labels, annotations and routes' do
expect do
subject.delete(space)
end.to change(VCAP::CloudController::Route, :count).by(-1)

expect { unmapped_route_1.refresh }.to raise_error Sequel::Error, 'Record not found'
expect { label_1.refresh }.to raise_error Sequel::Error, 'Record not found'
expect { annot_1.refresh }.to raise_error Sequel::Error, 'Record not found'
end
end
end
end
end

0 comments on commit 53eb8d9

Please sign in to comment.