Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EUWE] Return correct resource hrefs #15238

Merged
merged 1 commit into from Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/controllers/api/base_controller/renderer.rb
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
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
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
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