1

The response body is return the "formated json with Grape Entity", but the first_prefered is returning the complete object (json format).

How Can I convert the first_prefered object just to get the exposed fields using grape entity?

FeaturedHomekeeperResponseEntity:

module API::V1::Entities
  class FeaturedHomekeeperResponseEntity < Grape::Entity
    expose :id, documentation: { type: 'integer', desc: 'ID' }
    expose :featured_type, documentation: { type: 'string', desc: 'Featured Type' }
  end
end

Test:

let(:address) { Fabricate(:address) }

      it 'should return the first prefered homekeeper of an address' do
        first_prefered = Fabricate(:featured_homekeeper_as_first_prefered, address: address)

        get "/api/v1/addresses/#{address.id}/prefered/first"

        expect(json).to eq(YAML.load(first_prefered.to_json))
      end
4

2 に答える 2