Skip to content

Commit

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

Otherwise this operation gives a FK error.
  • Loading branch information
Samze committed Nov 20, 2024
1 parent eece70a commit ef40bbc
Show file tree
Hide file tree
Showing 2 changed files with 19 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
18 changes: 18 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,24 @@ 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' do
let!(:unmapped_route_1) { Route.make(domain: domain, space: space, host: 'unmapped1') }
let!(:unmapped_route_2) { Route.make(domain: domain, space: space, host: 'unmapped2') }
let!(:label_1) { RouteLabelModel.make(key_name: 'k1', value: 'v1', resource_guid: unmapped_route_1.guid) }
let!(:label_2) { RouteLabelModel.make(key_name: 'k2', value: 'v2', resource_guid: unmapped_route_2.guid) }

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

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

0 comments on commit ef40bbc

Please sign in to comment.