Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use destroy over delete for deleting unmapped routes #4100

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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