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

Fix expand of custom_actions when they are nil #305

Merged
merged 1 commit into from
Jan 29, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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