Skip to content

Commit

Permalink
If a custom action is being returned for a sub collection, the collec…
Browse files Browse the repository at this point in the history
…tion href should be returned because custom actions are not supported on sub resources.
  • Loading branch information
Jillian Tullo committed Dec 12, 2017
1 parent 3fe44cd commit 568fd68
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def add_actions(json, aspecs, type)
def expand_resource_custom_actions(resource, json, type, physical_attrs)
return unless render_actions(physical_attrs) && collection_config.custom_actions?(type)

href = json.attributes!["href"]
href = @req.subcollection.present? ? collection_href(@req.subcollection, resource.id) : json.attributes!["href"]
json.actions do |js|
resource_custom_action_names(resource).each do |action|
add_child js, "name" => action, "method" => :post, "href" => href
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/generic_object_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
'id' => object.id.to_s,
'name' => 'bar',
'property_attributes' => { 'is_something' => true },
'actions' => [{'name' => 'foo', 'method' => 'post', 'href' => api_generic_object_definition_generic_object_url(nil, object_def.id, object.id)}]
'actions' => [{'name' => 'foo', 'method' => 'post', 'href' => api_generic_object_url(nil, object.id)}]
}
expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
Expand Down

0 comments on commit 568fd68

Please sign in to comment.