Skip to content

Fix bug that would overwrite the content of the response body when using multiple presenters#784

Closed
mfunaro wants to merge 2 commits into
ruby-grape:masterfrom
mfunaro:multiple-presenters-with-Grape-entities
Closed

Fix bug that would overwrite the content of the response body when using multiple presenters#784
mfunaro wants to merge 2 commits into
ruby-grape:masterfrom
mfunaro:multiple-presenters-with-Grape-entities

Conversation

@mfunaro

@mfunaro mfunaro commented Oct 20, 2014

Copy link
Copy Markdown
Contributor

When using multiple presenters that make use of Grape Entity, if the user does not specify the root when calling the present method, the contents added to the body by the first presenter would be overwritten by the second presenter.

This issue becomes apparent when the user does not pass a root to the present method but instead opts to use the 'root' inside the Grape Entity being provided to present method.

…ing multiple presenters (utilizing the 'root' in the presenter rather than passing the root in the present method). Add conditional logic to inside_route#present that checks if we are using an entity, if so we merge appropriately so nothing is overwritten. Add test to inside_route_spec.rb.
Comment thread lib/grape/dsl/inside_route.rb Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mutually exclusive with above, change it to be something like

if key
   # ...
elsif ...
   # ...
end

@mfunaro

mfunaro commented Nov 10, 2014

Copy link
Copy Markdown
Contributor Author

Any additional thoughts on this one?

@dblock

dblock commented Nov 10, 2014

Copy link
Copy Markdown
Member

Sorry, I didn't see it was updated. Merged via 9cf4c7e. Thank you.

@dblock

dblock commented Jun 2, 2015

Copy link
Copy Markdown
Member

I ran into #1023 which was caused by this change. I am going to change respond_to?('merge') to a kind_of?(Hash), which might break something (but doesn't break specs, so I am going to go ahead). Please comment there if you think that's wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants