Skip to content

Commit 53eb8d9

Browse files
authored
Use destroy over delete for deleting unmapped routes (#4100)
This triggers the deletion of associated resources, like labels/annotations. Otherwise this operation gives a FK error.
1 parent f3834d2 commit 53eb8d9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/actions/space_delete_unmapped_routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def delete(space)
77
space.routes_dataset.
88
exclude(guid: RouteMappingModel.select(:route_guid)).
99
exclude(id: RouteBinding.select(:route_id)).
10-
delete
10+
destroy
1111
end
1212
end
1313
end

spec/unit/actions/space_delete_unmapped_routes_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ module VCAP::CloudController
7171
expect { unbound_and_unmapped_route.refresh }.to raise_error Sequel::Error, 'Record not found'
7272
end
7373
end
74+
75+
context 'when the unmapped routes have labels and annotations' do
76+
let!(:unmapped_route_1) { Route.make(domain: domain, space: space, host: 'unmapped1') }
77+
let!(:label_1) { RouteLabelModel.make(key_name: 'k1', value: 'v1', resource_guid: unmapped_route_1.guid) }
78+
let!(:annot_1) { RouteAnnotationModel.make(key_name: 'k1', value: 'v1', resource_guid: unmapped_route_1.guid) }
79+
80+
it 'deletes the labels, annotations and routes' do
81+
expect do
82+
subject.delete(space)
83+
end.to change(VCAP::CloudController::Route, :count).by(-1)
84+
85+
expect { unmapped_route_1.refresh }.to raise_error Sequel::Error, 'Record not found'
86+
expect { label_1.refresh }.to raise_error Sequel::Error, 'Record not found'
87+
expect { annot_1.refresh }.to raise_error Sequel::Error, 'Record not found'
88+
end
89+
end
7490
end
7591
end
7692
end

0 commit comments

Comments
 (0)