Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jillian Tullo committed May 26, 2017
1 parent 722994d commit 527450e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
9 changes: 5 additions & 4 deletions app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ 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)

return reftype if collection_class == rclass || collection_class.descendants.include?(rclass)

collection_config.name_for_klass(rclass) || reftype
end

#
Expand Down
21 changes: 19 additions & 2 deletions spec/requests/api/requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -363,5 +363,22 @@
expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
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
end
2 changes: 1 addition & 1 deletion spec/requests/api/service_catalogs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,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
Expand Down
1 change: 1 addition & 0 deletions spec/requests/api/tenant_quotas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 527450e

Please sign in to comment.