Skip to content

Why do I have to call .as_json twice to get a proper representation #313

Open
@bobbytables

Description

@bobbytables

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' do
  authed_get "/v1/incidents/#{incident.id}/related_change_events"

  expect(parsed['data']).to match_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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions