You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I'm trying to use my entity to ensure the returned data in the API matches what my Entity should be exposing in a RSpec request spec in my rails application.
I'm doing this:
it'returns the change events for the incident as json'doauthed_get"/v1/incidents/#{incident.id}/related_change_events"expect(parsed['data']).tomatch_array(PublicAPI::V1::Incidents::RelatedChangeEventEntity.represent(related_change_events).as_json.as_json)end
This makes my test pass, but why do I have to call #as_json twice? This feels weird to me and I don't see a method on the Grape::Entity class that gives me what I want. More of a question than a bug but I see room for improvement here.
Thanks!
The text was updated successfully, but these errors were encountered:
We're hitting this too, in a way. Calling .as_json doesn't seem to return a hash for nested entities. Oddly, calling .to_json will return a string that has been properly recursed and converted to json.
In other words, calling .as_json converts the top level entity to a hash, but nested entities remain as type: Grape::Entity::Exposure::NestingExposure::OutputBuilder. This means you can't do things like deep_stringify_keys or otherwise work with this structure.
I'm not sure, but I would guess you need to call .as_json for every level of nesting, its not just that its magically needing to call it twice.
Hi! I'm trying to use my entity to ensure the returned data in the API matches what my Entity should be exposing in a RSpec request spec in my rails application.
I'm doing this:
This makes my test pass, but why do I have to call
#as_json
twice? This feels weird to me and I don't see a method on theGrape::Entity
class that gives me what I want. More of a question than a bug but I see room for improvement here.Thanks!
The text was updated successfully, but these errors were encountered: