diff --git a/app/controllers/api/base_controller/renderer.rb b/app/controllers/api/base_controller/renderer.rb index 5f537a8672..433278527e 100644 --- a/app/controllers/api/base_controller/renderer.rb +++ b/app/controllers/api/base_controller/renderer.rb @@ -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 diff --git a/spec/requests/roles_spec.rb b/spec/requests/roles_spec.rb index b1dd0e20de..f25915347a 100644 --- a/spec/requests/roles_spec.rb +++ b/spec/requests/roles_spec.rb @@ -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 @@ -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 resource' do + api_basic_authorize action_identifier(:roles, :read, :resource_actions, :get) + + get(api_role_url(nil, role)) + + 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