Skip to content

Commit

Permalink
Fix ruby-grape#249: leaking of options and internals in default seria…
Browse files Browse the repository at this point in the history
…lization.
  • Loading branch information
dblock committed Nov 20, 2016
1 parent bca979c commit bce09f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#### Fixes

* [#249](https://github.com/ruby-grape/grape-entity/issues/249): Fix leaking of options and internals in default serialization - [@dblock](https://github.com/dblock), [@KingsleyKelly](https://github.com/KingsleyKelly).
* [#248](https://github.com/ruby-grape/grape-entity/pull/248): Fix `nil` values causing errors when `merge` option passed - [@arempe93](https://github.com/arempe93).
* Your contribution here.

Expand Down
5 changes: 5 additions & 0 deletions lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ def presented
end
end

# Prevent default serialization of :options or :delegator.
def inspect
"#<#{self.class.name}:#{self.object_id} @object=#{@object}>"
end

def initialize(object, options = {})
@object = object
@delegator = Delegator.new object
Expand Down
7 changes: 7 additions & 0 deletions spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,13 @@ class NoPathCharacterEntity < Grape::Entity
end
end

describe "#inspect" do
it 'does not serialize delegator or options' do
expect(subject.inspect).to_not include "@options"
expect(subject.inspect).to_not include "@delegator"
end
end

describe '#value_for' do
before do
fresh_class.class_eval do
Expand Down

0 comments on commit bce09f6

Please sign in to comment.