Skip to content

Commit 8f5b029

Browse files
sbatykovdblock
authored andcommitted
Fix: double pass options in serializable_hash (#219)
1 parent 8e81998 commit 8f5b029

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
============
33

44
* [#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).
5+
* [#219](https://github.com/ruby-grape/grape-entity/pull/219): Fix: double pass options in serializable_hash - [@sbatykov](https://github.com/sbatykov).
56
* Your contribution here.
67

78
0.5.1 (2016-4-4)

lib/grape_entity/exposure/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def serializable_value(entity, options)
6363
partial_output = valid_value(entity, options)
6464

6565
if partial_output.respond_to?(:serializable_hash)
66-
partial_output.serializable_hash(options)
66+
partial_output.serializable_hash
6767
elsif partial_output.is_a?(Array) && partial_output.all? { |o| o.respond_to?(:serializable_hash) }
6868
partial_output.map(&:serializable_hash)
6969
elsif partial_output.is_a?(Hash)

spec/grape_entity/hash_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'spec_helper'
2+
3+
describe Grape::Entity do
4+
it 'except option for nested entity' do
5+
module EntitySpec
6+
class Address < Grape::Entity
7+
expose :post, if: :full
8+
expose :city
9+
expose :street
10+
expose :house
11+
end
12+
13+
class Company < Grape::Entity
14+
expose :full_name, if: :full
15+
expose :name
16+
expose :address do |c, o|
17+
Address.represent c[:address], Grape::Entity::Options.new(o.opts_hash.except(:full))
18+
end
19+
end
20+
end
21+
22+
company = {
23+
full_name: 'full_name',
24+
name: 'name',
25+
address: {
26+
post: '123456',
27+
city: 'city',
28+
street: 'street',
29+
house: 'house',
30+
something_else: 'something_else'
31+
}
32+
}
33+
34+
expect(EntitySpec::Company.represent(company).serializable_hash).to eq \
35+
company.slice(:name).merge(address: company[:address].slice(:city, :street, :house))
36+
37+
expect(EntitySpec::Company.represent(company, full: true).serializable_hash).to eq \
38+
company.slice(:full_name, :name).merge(address: company[:address].slice(:city, :street, :house))
39+
end
40+
end

0 commit comments

Comments
 (0)