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-serializable-hash-option #219

Merged
merged 5 commits into from
Jun 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
============

* [#215](https://github.com/ruby-grape/grape-entity/pull/217): Fix: `#delegate_attribute` no longer delegates to methods included with `Kernel` - [@maltoe](https://github.com/maltoe).
* [#219](https://github.com/ruby-grape/grape-entity/pull/219): Fix: double pass options in serializable_hash - [@sbatykov](https://github.com/sbatykov).
* Your contribution here.

0.5.1 (2016-4-4)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape_entity/exposure/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def serializable_value(entity, options)
partial_output = valid_value(entity, options)

if partial_output.respond_to?(:serializable_hash)
partial_output.serializable_hash(options)
partial_output.serializable_hash
elsif partial_output.is_a?(Array) && partial_output.all? { |o| o.respond_to?(:serializable_hash) }
partial_output.map(&:serializable_hash)
elsif partial_output.is_a?(Hash)
Expand Down
40 changes: 40 additions & 0 deletions spec/grape_entity/hash_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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