Skip to content

Commit

Permalink
This fixes a regression where subcollections are not being returned f…
Browse files Browse the repository at this point in the history
…or a resource even when it is configured to be returned within the api.yml.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1529299
  • Loading branch information
Jillian Tullo committed Jan 5, 2018
1 parent fdf9ac5 commit a921fb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def expand_subcollection?(sc, target)

# Expand if: expand='resources' && no attributes specified && subcollection is configured
def expand_resources?(sc)
@req.expand?('resources') && @req.attributes.empty? && collection_config.show?(sc)
collection_config.show?(sc) && (@req.collection_id || @req.expand?('resources')) && @req.attributes.empty?
end

# Expand if: resource is being returned and subcollection is configured
Expand Down
26 changes: 23 additions & 3 deletions spec/requests/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ def test_features_query(role, role_url, klass, attr = :id)
end

describe "Features" do
let(:role) { FactoryGirl.create(:miq_user_role, :name => "Test Role", :miq_product_features => @product_features) }

it "query available features" do
role = FactoryGirl.create(:miq_user_role,
:name => "Test Role",
:miq_product_features => @product_features)
test_features_query(role, api_role_url(nil, role), MiqProductFeature, :identifier)
end

Expand All @@ -89,6 +88,27 @@ def test_features_query(role, role_url, klass, attr = :id)
expect(response).to have_http_status(:ok)
response.parsed_body['resources'].each { |res| expect_hash_to_have_only_keys(res, %w(href id name)) }
end

it 'returns features by default when expanding the collection resources' do
api_basic_authorize action_identifier(:roles, :read, :collection_actions, :get)

get(api_roles_url, :params => { :expand => 'resources' })

expect(response).to have_http_status(:ok)
expect_result_resources_to_include_keys('resources', %w(features))
end

it 'returns features by default for a role reseource' do
api_basic_authorize action_identifier(:roles, :read, :resource_actions, :get)

get(api_role_url(nil, role), :params => { :expand => 'resources' })

expected = {
'features' => a_collection_including('href' => a_string_including(api_role_features_url(nil, role, nil)))
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

describe "Roles create" do
Expand Down

0 comments on commit a921fb0

Please sign in to comment.