diff --git a/app/controllers/api/subcollections/cloud_tenants.rb b/app/controllers/api/subcollections/cloud_tenants.rb index 9d658913da..93bb65bed0 100644 --- a/app/controllers/api/subcollections/cloud_tenants.rb +++ b/app/controllers/api/subcollections/cloud_tenants.rb @@ -2,7 +2,7 @@ module Api module Subcollections module CloudTenants def cloud_tenants_query_resource(object) - object.cloud_tenants + object.respond_to?(:cloud_tenants) ? object.cloud_tenants : [] end end end diff --git a/app/controllers/api/subcollections/flavors.rb b/app/controllers/api/subcollections/flavors.rb index be194646c6..f07a05864c 100644 --- a/app/controllers/api/subcollections/flavors.rb +++ b/app/controllers/api/subcollections/flavors.rb @@ -2,7 +2,7 @@ module Api module Subcollections module Flavors def flavors_query_resource(object) - object.flavors + object.respond_to?(:flavors) ? object.flavors : [] end def flavors_create_resource(parent, _type, _id, data) diff --git a/spec/requests/cloud_tenants_spec.rb b/spec/requests/cloud_tenants_spec.rb index f083a2c43a..d2d54c1bc5 100644 --- a/spec/requests/cloud_tenants_spec.rb +++ b/spec/requests/cloud_tenants_spec.rb @@ -93,4 +93,16 @@ expect(response).to have_http_status(:forbidden) end end + + context 'As a subcollection' do + it 'returns an empty array for collections that do not have cloud tenants' do + ems_infra = FactoryGirl.create(:ems_infra) + api_basic_authorize(subcollection_action_identifier(:providers, :cloud_tenants, :read, :get)) + + get(api_provider_cloud_tenants_url(nil, ems_infra)) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include('resources' => []) + end + end end diff --git a/spec/requests/flavors_spec.rb b/spec/requests/flavors_spec.rb index b5db4b3ce6..f8fd71506c 100644 --- a/spec/requests/flavors_spec.rb +++ b/spec/requests/flavors_spec.rb @@ -28,6 +28,16 @@ expect(response).to have_http_status(:forbidden) end + + it 'returns an empty array for collections that do not have flavors' do + ems_infra = FactoryGirl.create(:ems_infra) + api_basic_authorize(subcollection_action_identifier(:providers, :flavors, :read, :get)) + + get(api_provider_flavors_url(nil, ems_infra)) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include('resources' => []) + end end describe "GET /api/providers/:c_id/flavors/:id" do