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 bug that would overwrite the content of the response body when using multiple presenters #784

Closed
wants to merge 2 commits into from
Closed

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

wants to merge 2 commits into from

Conversation

mfunaro
Copy link
Contributor

@mfunaro mfunaro commented Oct 20, 2014

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.
@@ -188,6 +188,13 @@ def present(*args)

representation = { root => representation } if root
representation = (@body || {}).merge(key => representation) if key

# If root and key are nil but we have entity, merge using the representation from entity.
Copy link
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
Copy link
Contributor Author

mfunaro commented Nov 10, 2014

Any additional thoughts on this one?

@dblock
Copy link
Member

dblock commented Nov 10, 2014

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

@dblock
Copy link
Member

dblock commented Jun 2, 2015

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