diff --git a/app/actions/space_delete_unmapped_routes.rb b/app/actions/space_delete_unmapped_routes.rb index b43913c1c0d..ae6d3506a76 100644 --- a/app/actions/space_delete_unmapped_routes.rb +++ b/app/actions/space_delete_unmapped_routes.rb @@ -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 diff --git a/spec/unit/actions/space_delete_unmapped_routes_spec.rb b/spec/unit/actions/space_delete_unmapped_routes_spec.rb index 12922efe0b0..b515abea6ed 100644 --- a/spec/unit/actions/space_delete_unmapped_routes_spec.rb +++ b/spec/unit/actions/space_delete_unmapped_routes_spec.rb @@ -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