Skip to content

Commit

Permalink
Merge pull request #322 from jntullo/subcollections
Browse files Browse the repository at this point in the history
Ensure array is returned for subcollections
(cherry picked from commit f9f9d88)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1552826
  • Loading branch information
abellotti authored and simaishi committed Mar 7, 2018
1 parent deb7a2b commit c640ef6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/subcollections/cloud_networks.rb
Expand Up @@ -2,7 +2,7 @@ module Api
module Subcollections
module CloudNetworks
def cloud_networks_query_resource(object)
object.respond_to?(:cloud_networks) ? object.cloud_networks : []
object.respond_to?(:cloud_networks) ? Array(object.cloud_networks) : []
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/subcollections/cloud_subnets.rb
Expand Up @@ -2,7 +2,7 @@ module Api
module Subcollections
module CloudSubnets
def cloud_subnets_query_resource(object)
object.cloud_subnets
object.respond_to?(:cloud_subnets) ? Array(object.cloud_subnets) : []
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/subcollections/security_groups.rb
Expand Up @@ -2,7 +2,7 @@ module Api
module Subcollections
module SecurityGroups
def security_groups_query_resource(object)
object.respond_to?(:security_groups) ? object.security_groups : []
object.respond_to?(:security_groups) ? Array(object.security_groups) : []
end

def security_groups_add_resource(parent, _type, _id, data)
Expand Down
32 changes: 32 additions & 0 deletions spec/requests/providers_spec.rb
Expand Up @@ -1091,6 +1091,16 @@ def gen_import_request

expect(response).to have_http_status(:forbidden)
end

it "returns an empty array for providers that return nil" do
api_basic_authorize subcollection_action_identifier(:providers, :cloud_subnets, :read, :get)
provider = FactoryGirl.create(:ems_redhat)

get(api_provider_cloud_subnets_url(nil, provider))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include("resources" => [])
end
end

context 'cloud tenants subcollection' do
Expand Down Expand Up @@ -1199,6 +1209,16 @@ def gen_import_request

expect(response).to have_http_status(:forbidden)
end

it "returns an empty array for providers that return nil" do
api_basic_authorize subcollection_action_identifier(:providers, :security_groups, :read, :get)
provider = FactoryGirl.create(:ems_redhat)

get(api_provider_security_groups_url(nil, provider))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include("resources" => [])
end
end

describe 'edit custom_attributes on providers' do
Expand Down Expand Up @@ -1274,4 +1294,16 @@ def gen_import_request
expect(response.parsed_body).to include(expected)
end
end

context "Cloud networks subcollection" do
it "returns an empty array for providers that return nil" do
api_basic_authorize subcollection_action_identifier(:providers, :cloud_networks, :read, :get)
provider = FactoryGirl.create(:ems_redhat)

get(api_provider_cloud_networks_url(nil, provider))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include("resources" => [])
end
end
end

0 comments on commit c640ef6

Please sign in to comment.