Sha256: 3defaef8f236981d3aff7c45de4edad6051e4870e878b0ec3c86d0bd04544918
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true require 'spec_helper' describe Grape::Entity do it 'except option for nested entity' do module EntitySpec class Address < Grape::Entity expose :post, if: :full expose :city expose :street expose :house end class Company < Grape::Entity expose :full_name, if: :full expose :name expose :address do |c, o| Address.represent c[:address], Grape::Entity::Options.new(o.opts_hash.except(:full)) end end end company = { full_name: 'full_name', name: 'name', address: { post: '123456', city: 'city', street: 'street', house: 'house', something_else: 'something_else' } } expect(EntitySpec::Company.represent(company).serializable_hash).to eq \ company.slice(:name).merge(address: company[:address].slice(:city, :street, :house)) expect(EntitySpec::Company.represent(company, full: true).serializable_hash).to eq \ company.slice(:full_name, :name).merge(address: company[:address].slice(:city, :street, :house)) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
grape-entity-0.7.1 | spec/grape_entity/hash_spec.rb |
grape-entity-0.7.0 | spec/grape_entity/hash_spec.rb |