Skip to content

Commit

Permalink
Do not attempt to expand custom action hrefs if the resource does not…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jillian Tullo committed Jan 29, 2018
1 parent f5f0c38 commit 42c326e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def fetch_direct_virtual_attribute(type, resource, attr)
# will not be overwritten later.
#
def add_custom_action_hrefs(value)
return if value.nil?
result = value.dup
result[:buttons].each do |button|
button["href"] = normalize_href(:custom_buttons, button["id"])
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/custom_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def expect_result_to_have_custom_actions_hash
end

describe "Querying services with no custom actions" do
let(:service) { FactoryGirl.create(:service) }

it "returns core actions as authorized" do
api_basic_authorize(action_identifier(:services, :edit),
action_identifier(:services, :read, :resource_actions, :get))
Expand All @@ -77,6 +79,16 @@ def expect_result_to_have_custom_actions_hash
expect_result_to_have_keys(%w(id href actions))
expect(response.parsed_body["actions"].select { |a| a["method"] == "post" }.pluck("name")).to match_array(%w(edit add_resource remove_resource remove_all_resources add_provider_vms))
end

it "allows expanding of custom actions" do
api_basic_authorize(collection_action_identifier(:services, :read, :get))

expected = { 'resources' => a_collection_including(a_hash_including('id' => service.id.to_s)) }
get(api_services_url, :params => { :expand => "resources", :attributes => "custom_actions" })

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

describe "Querying services with custom actions" do
Expand Down

0 comments on commit 42c326e

Please sign in to comment.