Skip to content

Commit 173ff49

Browse files
philippthunjohha
authored andcommitted
Fix select query for service offerings
The service offerings list fetcher returned duplicates in case an offering had both a public plan and another plan that was org restricted. Thus a DISTINCT has been added to the outer select query.
1 parent 269c885 commit 173ff49

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

app/fetchers/service_offering_list_fetcher.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ module VCAP::CloudController
44
class ServiceOfferingListFetcher < BaseServiceListFetcher
55
class << self
66
def fetch(message, omniscient: false, readable_orgs_query: nil, readable_spaces_query: nil, eager_loaded_associations: [])
7-
super(Service,
8-
message,
9-
omniscient:,
10-
readable_orgs_query:,
11-
readable_spaces_query:,
12-
eager_loaded_associations:)
7+
dataset = super(Service,
8+
message,
9+
omniscient:,
10+
readable_orgs_query:,
11+
readable_spaces_query:,
12+
eager_loaded_associations:)
13+
# for service offerings there might be an overlap between the UNIONed subqueries (i.e. one plan is public and another one is org restricted)
14+
dataset.distinct
1315
end
1416

1517
private

spec/unit/fetchers/service_offering_list_fetcher_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ module VCAP::CloudController
1818
end
1919
end
2020

21+
context 'service offering with both public and org restricted plans' do
22+
let(:org) { Organization.make }
23+
let(:readable_orgs) { [org] }
24+
25+
it 'shows unique results' do
26+
service_offering = Service.make(label: "with-public-and-org-restricted-plans-#{Sham.name}")
27+
ServicePlan.make(public: true, active: true, service: service_offering)
28+
service_plan = ServicePlan.make(public: false, service: service_offering)
29+
ServicePlanVisibility.make(organization: org, service_plan: service_plan)
30+
31+
service_offerings = fetcher.fetch(message, readable_orgs_query:).all
32+
expect(service_offerings).to contain_exactly(service_offering)
33+
end
34+
end
35+
2136
describe 'visibility of offerings' do
2237
let!(:public_offering_1) { make_public_offering }
2338
let!(:public_offering_2) { make_public_offering(number_of_plans: 2) }

0 commit comments

Comments
 (0)