From 760c5e29ab4bb91770f334cb31fbc00bea328646 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Tue, 28 Mar 2017 15:10:50 -0400 Subject: [PATCH] fixes https://bugzilla.redhat.com/show_bug.cgi?id=1418331 return retype is no name for klass --- .../api/base_controller/renderer.rb | 10 +++++---- spec/requests/api/requests_spec.rb | 21 +++++++++++++++++-- spec/requests/api/service_catalogs_spec.rb | 2 +- spec/requests/api/tenant_quotas_spec.rb | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/base_controller/renderer.rb b/app/controllers/api/base_controller/renderer.rb index 9bd9dbb221d..b8be00df0b6 100644 --- a/app/controllers/api/base_controller/renderer.rb +++ b/app/controllers/api/base_controller/renderer.rb @@ -75,10 +75,12 @@ def get_reftype(type, reftype, resource, _opts = {}) return reftype unless resource.respond_to?(:attributes) rclass = resource.class - if collection_class(type) != rclass - matched_type = collection_config.name_for_klass(rclass) - end - matched_type || reftype + collection_class = collection_class(type) + + # Ensures hrefs are consistent with those of the collection they were requested from + return reftype if collection_class == rclass || collection_class.descendants.include?(rclass) + + collection_config.name_for_klass(rclass) || reftype end # diff --git a/spec/requests/api/requests_spec.rb b/spec/requests/api/requests_spec.rb index 5e09bb3fc8b..adee2c6554a 100644 --- a/spec/requests/api/requests_spec.rb +++ b/spec/requests/api/requests_spec.rb @@ -67,7 +67,7 @@ expect(response).to have_http_status(:ok) expect(response.parsed_body).to include("id" => service_request.id, - "href" => a_string_matching(service_requests_url(service_request.id))) + "href" => a_string_matching(requests_url(service_request.id))) end it "lists all the service requests if you are admin" do @@ -110,7 +110,7 @@ expected = { "id" => service_request.id, - "href" => a_string_matching(service_requests_url(service_request.id)) + "href" => a_string_matching(requests_url(service_request.id)) } expect(response).to have_http_status(:ok) expect(response.parsed_body).to include(expected) @@ -445,4 +445,21 @@ expect(response).to have_http_status(:ok) end end + + context "resource hrefs" do + it "returns the requests href reference for objects of different subclasses" do + provision_request = FactoryGirl.create(:service_template_provision_request, :requester => @user) + automation_request = FactoryGirl.create(:automation_request, :requester => @user) + api_basic_authorize collection_action_identifier(:requests, :read, :get) + + run_get requests_url, :expand => :resources + + expected = [ + a_hash_including('href' => a_string_including(requests_url(provision_request.id))), + a_hash_including('href' => a_string_including(requests_url(automation_request.id))) + ] + expect(response).to have_http_status(:ok) + expect(response.parsed_body['resources']).to match_array(expected) + end + end end diff --git a/spec/requests/api/service_catalogs_spec.rb b/spec/requests/api/service_catalogs_spec.rb index f25dc3ce9ef..7fa454c673f 100644 --- a/spec/requests/api/service_catalogs_spec.rb +++ b/spec/requests/api/service_catalogs_spec.rb @@ -396,7 +396,7 @@ def init_st(service_template, resource_action) run_post(sc_templates_url(sc.id, st1.id), gen_request(:order)) - expect_single_resource_query(order_request) + expect_single_resource_query(order_request.merge("href" => /service_requests/)) end it "accepts order requests with required fields" do diff --git a/spec/requests/api/tenant_quotas_spec.rb b/spec/requests/api/tenant_quotas_spec.rb index 978f4dc12a8..b2634972da1 100644 --- a/spec/requests/api/tenant_quotas_spec.rb +++ b/spec/requests/api/tenant_quotas_spec.rb @@ -76,6 +76,7 @@ expect(response).to have_http_status(:ok) quota.reload expect(quota.value).to eq(5) + expect(response.parsed_body).to include('href' => /quotas/) end it "can update multiple quotas from a tenant with POST" do