Skip to content

Commit 7348c43

Browse files
authored
don't return the same route multiple times when shared to more then 2 spaces (#4702)
* don't return the same route multiple times when shared to more then 2 spaces * similar to what's been done with service instances #3955, if a route is shared to more then two spaces, it will show up many times in the result
1 parent ab19ce6 commit 7348c43

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

app/fetchers/route_fetcher.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def fetch(message, readable_space_guids_dataset: nil, eager_loaded_associations:
1414
(Sequel[:route_shares][:target_space_guid] =~ readable_space_guids_dataset)
1515
end
1616
end
17+
dataset = dataset.distinct(Sequel[:routes][:guid])
1718
filter(message, dataset)
1819
end
1920

spec/unit/fetchers/route_fetcher_spec.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module VCAP::CloudController
77
describe '.fetch' do
88
before do
99
Route.dataset.destroy
10-
# shared_route.add_shared_space(space2)
1110
end
1211

1312
let!(:space1) { Space.make }
@@ -17,7 +16,6 @@ module VCAP::CloudController
1716
let!(:route1) { Route.make(guid: 'route1_guid', host: 'host1', path: '/path1', space: space1, domain: domain1) }
1817
let!(:route2) { Route.make(guid: 'route2_guid', host: 'host2', path: '/path2', space: space1, domain: domain1) }
1918
let!(:route3) { Route.make(guid: 'route3_guid', host: 'host3', path: '/path1', space: space2, domain: domain2) }
20-
# let!(:shared_route) { Route.make(guid: 'shared_route_guid', host: 'host2', path: '/path1', space: space1, domain: domain2) }
2119

2220
let(:message) do
2321
RoutesListMessage.from_params(routes_filter)
@@ -30,14 +28,22 @@ module VCAP::CloudController
3028
expect(RouteFetcher.fetch(message, omniscient: true).all).to contain_exactly(route1, route2, route3)
3129
end
3230

31+
it 'does not duplicate routes when shared' do
32+
space3 = Space.make
33+
shared_route = Route.make(guid: 'shared_route_guid', host: 'host1', path: '/path_shared', space: space1, domain: domain1)
34+
shared_route.add_shared_space(space2)
35+
shared_route.add_shared_space(space3)
36+
expect(RouteFetcher.fetch(message, omniscient: true).all).to contain_exactly(route1, route2, route3, shared_route)
37+
end
38+
3339
it 'fetches the routes owned by readable spaces' do
3440
dataset = RouteFetcher.fetch(message, readable_space_guids_dataset: Space.where(id: [space1.id]).select(:guid))
3541
expect(dataset.all).to contain_exactly(route1, route2)
3642
end
3743

3844
it 'fetches the instances shared to readable spaces' do
39-
space4 = Space.make
40-
shared_route = Route.make(space: space4)
45+
space3 = Space.make
46+
shared_route = Route.make(space: space3)
4147
shared_route.add_shared_space(space2)
4248
dataset = RouteFetcher.fetch(message, readable_space_guids_dataset: Space.where(id: [space2.id]).select(:guid))
4349
expect(dataset.all).to contain_exactly(route3, shared_route)

0 commit comments

Comments
 (0)